none
How do I bind data from a table adapter to controls on a WinForm?

    Question

  • I realize that this is "old school", but I'm going to ask it anyway.

    I am trying to figure out how to bind data from a table adapter to controls on a WinForm.  I've got one form, where I perform a search and put all of the returned data into a DataGridView, by assigning data to the DataSource property of the DataGridView.  Cool, this works fine.

    After the user selects a row from the DataGridView and moves onto another WinForm, I pass in parameters to another table adapter on the second WinForm.  It is to return detail information using the selection criteria specified in the first WinForm.  I've tested the data in the debugger, and it is returning the correct data.  I just don't have how to assign the data from each of the 2 tables in the second WinForm to the controls on the WinForm.  I don't know how to do it either programmatically or declaratively, and I would appreciate some help on this, please.

    I'm using C# in VS 2008.

     

    Monday, October 20, 2008 9:46 PM

Answers

  •  Rod at Work wrote:
    I realize that this is "old school", but I'm going to ask it anyway.

    I am trying to figure out how to bind data from a table adapter to controls on a WinForm.  I've got one form, where I perform a search and put all of the returned data into a DataGridView, by assigning data to the DataSource property of the DataGridView.  Cool, this works fine.

    After the user selects a row from the DataGridView and moves onto another WinForm, I pass in parameters to another table adapter on the second WinForm.  It is to return detail information using the selection criteria specified in the first WinForm.  I've tested the data in the debugger, and it is returning the correct data.  I just don't have how to assign the data from each of the 2 tables in the second WinForm to the controls on the WinForm.  I don't know how to do it either programmatically or declaratively, and I would appreciate some help on this, please.

    I'm using C# in VS 2008.

     

    http://windowsclient.net/blogs/faqs/archive/tags/DataGridView/default.aspx

    http://msdn.microsoft.com/en-us/library/fbk67b6z(VS.80).aspx

     

    Let us know if these links help?

     

    Rudedog   =8^D

    Tuesday, October 21, 2008 12:25 AM
  • Hi Rod,

     

    I think Rudedog2 is reasonable, we can’t expect we can find some code that can do everything we need, but we can get the most valuable things from it. You requirement is very common, so I want to give you some general steps for you to follow.

     

    1.       When you choose one record from the main form, we can get the value of some certain field which we will use as a clause to filter records in another table.

    2.       Use SQL statement like “select * from datatable where field =’**'" to query the datatable. The value of the field is passed from main form.

    3.       We first use a DataAdapter to fill one dataset, and then create a BindingSource which is bound to the dataset.

    4.       We use simple list bingding to bind the TextBox and any other controls to the BindingSource. Like: this.TextBox.DataBindings.Add(“Text”,bindingSource,”field”).

     

    If you have further problems, please feel free to let me know.

     

    Best Regards,

    Bruce Zhou

     

    Thursday, October 23, 2008 12:02 PM

All replies

  •  Rod at Work wrote:
    I realize that this is "old school", but I'm going to ask it anyway.

    I am trying to figure out how to bind data from a table adapter to controls on a WinForm.  I've got one form, where I perform a search and put all of the returned data into a DataGridView, by assigning data to the DataSource property of the DataGridView.  Cool, this works fine.

    After the user selects a row from the DataGridView and moves onto another WinForm, I pass in parameters to another table adapter on the second WinForm.  It is to return detail information using the selection criteria specified in the first WinForm.  I've tested the data in the debugger, and it is returning the correct data.  I just don't have how to assign the data from each of the 2 tables in the second WinForm to the controls on the WinForm.  I don't know how to do it either programmatically or declaratively, and I would appreciate some help on this, please.

    I'm using C# in VS 2008.

     

    http://windowsclient.net/blogs/faqs/archive/tags/DataGridView/default.aspx

    http://msdn.microsoft.com/en-us/library/fbk67b6z(VS.80).aspx

     

    Let us know if these links help?

     

    Rudedog   =8^D

    Tuesday, October 21, 2008 12:25 AM
  • Hi Rudedog,

     

    Thank you for the link to Windowsclient.net.  I wasn't aware of that website. 

     

    The link you provided isn't exactly what I'm looking for.  On the second WinForm that I bring up I want to bind data to several controls on the form, like textboxes, DateTimePickers, etc, using a table adapter as the data source.

     

     

    Tuesday, October 21, 2008 3:08 PM
  • It is rare that you can find a code sample that does everything exactly as you need it. 

     

    I suggest that you take a peek at the NorthWinds database samples.  Or you could let the designer create a sample binding and simply copy the code that does what you need.

     

    Rudedog

     

    Tuesday, October 21, 2008 6:18 PM
  • Hi Rod,

     

    I think Rudedog2 is reasonable, we can’t expect we can find some code that can do everything we need, but we can get the most valuable things from it. You requirement is very common, so I want to give you some general steps for you to follow.

     

    1.       When you choose one record from the main form, we can get the value of some certain field which we will use as a clause to filter records in another table.

    2.       Use SQL statement like “select * from datatable where field =’**'" to query the datatable. The value of the field is passed from main form.

    3.       We first use a DataAdapter to fill one dataset, and then create a BindingSource which is bound to the dataset.

    4.       We use simple list bingding to bind the TextBox and any other controls to the BindingSource. Like: this.TextBox.DataBindings.Add(“Text”,bindingSource,”field”).

     

    If you have further problems, please feel free to let me know.

     

    Best Regards,

    Bruce Zhou

     

    Thursday, October 23, 2008 12:02 PM