T
Tony Johansson
Hello!
This is just for learing how all fits together.
I have this event handler button1_Click below
The sql clause for supplierTableAdapter is
SELECT SupplierID, CompanyName
FROM Suppliers
I have also a combobox where the DataSource is set to suppliersBindingSource
and DisplayMember to CompanyName and ValueMember to SupplierID
So when I click button1 all CompanyName is listed in the combobox which is
was I was expected. So this works good.
Now to my question: If I comment out these two rows
suppliersTableAdapter.Connection = dataConnection;
dataConnection.Open();
in the event handler and
run again it works just as good as it did before.
So how can it works when I don't have these two rows.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString = "Integrated Security=true;" +
"Initial Catalog=Northwind;" +
"Data Source=hempc\\SQLExpress";
suppliersTableAdapter.Connection = dataConnection;
dataConnection.Open();
suppliersTableAdapter.Fill(northwindDataSet.Suppliers);
}
//Tony
This is just for learing how all fits together.
I have this event handler button1_Click below
The sql clause for supplierTableAdapter is
SELECT SupplierID, CompanyName
FROM Suppliers
I have also a combobox where the DataSource is set to suppliersBindingSource
and DisplayMember to CompanyName and ValueMember to SupplierID
So when I click button1 all CompanyName is listed in the combobox which is
was I was expected. So this works good.
Now to my question: If I comment out these two rows
suppliersTableAdapter.Connection = dataConnection;
dataConnection.Open();
in the event handler and
run again it works just as good as it did before.
So how can it works when I don't have these two rows.
private void button1_Click(object sender, EventArgs e)
{
SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString = "Integrated Security=true;" +
"Initial Catalog=Northwind;" +
"Data Source=hempc\\SQLExpress";
suppliersTableAdapter.Connection = dataConnection;
dataConnection.Open();
suppliersTableAdapter.Fill(northwindDataSet.Suppliers);
}
//Tony