|
-
Jun 16th, 2007, 08:43 PM
#1
Thread Starter
Fanatic Member
help with binding
hi guys! help please..how will bind my texbox (TxtLastName) to my dataset (dsLastName) column (User_LastName). Thanks in avdance!
-
Jun 16th, 2007, 11:40 PM
#2
Re: help with binding
DataSets don't have columns. DataSets have tables and DataTables have columns.
Assuming that this is .NET 2.0 (please specify EVERY time) you should bind your data to a BindingSource and the BindingSource to your control(s). If you've added the DataSet in the designer then you should set up the binding in the designer as well, otherwise do it in code. In code it would look something like this:
C# Code:
myBindingSource.DataMember = "table name here";
myBindingSource.DataSource = myDataSet;
myTextBox.DataBindings.Add("Text", myBindingSource, "column name here");
Instead of the first two lines you could also do this:
Code:
myBindingSource.DataSource = myDataSet.Tables["table name here"];
-
Jun 16th, 2007, 11:58 PM
#3
Thread Starter
Fanatic Member
Re: help with binding
oh! sorry for that Jm...anyway, i'll try that..Thanks a lot!
-
Jun 17th, 2007, 10:08 PM
#4
Thread Starter
Fanatic Member
Re: help with binding
I have already tried your solution JM and it works..But, i have a follow-up quesions, Is it posible to unbind myBindingSource from myTextBox? and If I make an update from my Datatable's row is it posible to "Return" the Dataset to the sql server so that the updates will be applied to sql server also?
-
Jun 17th, 2007, 10:29 PM
#5
Re: help with binding
The DataBindings property of a control is a collection of Bindings. To add an item the the collection you call the Add method. How do you usually remove items from collections.
Saving data to a database has nothing to do with data-binding. You used a DataAdapter or TableAdapter to populate your DataTable in the first place. You use the same adapter to save any changes made to that DataTable back to the database, whether it was bound to a control or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|