Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine DataBindings at runtime
Message
From
22/09/2005 08:04:31
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01051886
Message ID:
01051904
Views:
10
>Hello all, I have a form whose textboxes can be bound to either of two DataSets, is there a way to determine which DataSet they're bound to at runtime ?
>
>// pseudo code
>
>
>if(this.txtAddr1.DataBinding is MyDataSet1)
>    someaction;
>else
>        someotheraction;
>
>
Pete,
if (this.txtAddr1.DataBindings["Text"].DataSource is MyDataSet1)
Would work but it'd only look for if they're of same type (class). If you have multiple instances of MyDataSet1 (with desingner generated datasets unlikely) which might have different datasets then you'd only be checking like ( if myTextBox's class is same as MyDataSet1 class ).
Aaargh, I can't even understand it when I write in plain English:)
Consider this:

DataSet ds1 = new DataSet("Northwind");
DataSet ds2 = new DataSet("Pubs");
// populated their tables

Binding 2 textboxes to some field from each one of those:

if (this.txt1.DataBindings["Text"].DataSource is DataSet)
if (this.txt2.DataBindings["Text"].DataSource is DataSet)

both return true. They both directly are derived from DataSet. What I want to know is if txt1 uses DataSet 'ds1', right? So:
if (this.txtAddr1.DataBindings["Text"].DataSource.Equals(this.dsName))
dsName refers to instance name on form. Likely in your case it's 'myDataSet1'.
The difference is that this makes an 'object' comparison between DataSource and 'YourDataSet'.
PS: You wouldn't believe I actually wrote this about 2 hrs ago. Internet was disconnected:( Hope now send succeeds.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform