Click to See Complete Forum and Search --> : help with binding
daimous
Jun 16th, 2007, 08:43 PM
hi guys! help please..how will bind my texbox (TxtLastName) to my dataset (dsLastName) column (User_LastName). Thanks in avdance!
jmcilhinney
Jun 16th, 2007, 11:40 PM
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: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:myBindingSource.DataSource = myDataSet.Tables["table name here"];
daimous
Jun 16th, 2007, 11:58 PM
oh! sorry for that Jm...anyway, i'll try that..Thanks a lot!
daimous
Jun 17th, 2007, 10:08 PM
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?
jmcilhinney
Jun 17th, 2007, 10:29 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.