I have this code
DataTable dt= new DataTable();
SqlDataAdapter da;
private void LoadData()
{
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnn"].ConnectionString))
{
da = new SqlDataAdapter("Select * from table",cnn);
da.Fill(dt);
}
}
The connection will be closed after, right?
If i want to update the DataTable, how can i reconnect da to cnn?
Yes, the using statement will call Dispose on the SqlConnection. See using Statement.
To reconnect in this fashion you’d need another using statement to do your update or update within the original using statement.