Results 1 to 5 of 5

Thread: help with binding

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    help with binding

    hi guys! help please..how will bind my texbox (TxtLastName) to my dataset (dsLastName) column (User_LastName). Thanks in avdance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. myBindingSource.DataMember = "table name here";
    2. myBindingSource.DataSource = myDataSet;
    3.  
    4. 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"];
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: help with binding

    oh! sorry for that Jm...anyway, i'll try that..Thanks a lot!

  4. #4

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width