The following code is used to bind the controls in a form to a bindingsource.
SqlDataAdapter myAdapter; DataSet myDataSet; BindingSource myBinding;
This code can be placed inside the form's load event to create a bindingsource object and bind the controls to the bindingsource. This example uses the Customers table in the northwind sample database.
string connstring = "Data Source=.;Integrated Security=True;Initial Catalog=northwind"; myAdapter = new SqlDataAdapter("select * from customers", connstring); myAdapter.TableMappings.Add("Customers", "Customers"); myDataSet = new DataSet(); myAdapter.Fill(myDataSet, "Customers"); myBinding = new BindingSource(myDataSet, "Customers"); this.textBox1.DataBindings.Add(new Binding("Text", myBinding, "Customerid", true)); this.textBox2.DataBindings.Add(new Binding("Text", myBinding, "CompanyName", true)); MessageBox.Show("Binding source created and Controls are data-bound");
|
No responses found. Be the first to respond and make money from revenue sharing program.
|