I am using a GridView and wonder if it’s better for me to close the connection IMMEDIATELY after the
adapter.Fill(ds);
statement or I should wait until I’ve done:
GridView.DataSource = ds;
GridView.DataBind();
I assume once the dataset has been filled, I no longer need the connection. Am I wrong?
When you call
adapter.Fill(ds);the data is loaded into memory and you can close the connection immediately after this statement. After, when you set ds as DataSource to the gridview, it will bind the data from memory.Have a look into this article for understanding Working with Disconnected Data – The DataSet and SqlDataAdapter