Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 12, 2012 12:53 AM by Paul Linton
Member
7 Points
52 Posts
Aug 11, 2012 11:32 PM|LINK
Do I need to open and close a Sqlconnection, when I use dataset? I works fine out.
public DataSet SelectRows(DataSet dataset, SqlConnection connectionString, string queryString) { //connectionString.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(queryString, connectionString); adapter.Fill(dataset); //connectionString.Close(); return dataset; }
Normally I would close the Sqlconnection. But is it necessary here?
All-Star
16797 Points
2608 Posts
MVP
Aug 11, 2012 11:47 PM|LINK
No the data adapter will open and close the connection for you
Star
13431 Points
2535 Posts
Aug 12, 2012 12:53 AM|LINK
Ken Tucker the data adapter will open and close the connection for you
mhp3970
Member
7 Points
52 Posts
Do I need conn.Close() in dataset?
Aug 11, 2012 11:32 PM|LINK
Do I need to open and close a Sqlconnection, when I use dataset? I works fine out.
public DataSet SelectRows(DataSet dataset, SqlConnection connectionString, string queryString) { //connectionString.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(queryString, connectionString); adapter.Fill(dataset); //connectionString.Close(); return dataset; }Normally I would close the Sqlconnection. But is it necessary here?
Ken Tucker
All-Star
16797 Points
2608 Posts
MVP
Re: Do I need conn.Close() in dataset?
Aug 11, 2012 11:47 PM|LINK
No the data adapter will open and close the connection for you
Space Coast .Net User Group
Paul Linton
Star
13431 Points
2535 Posts
Re: Do I need conn.Close() in dataset?
Aug 12, 2012 12:53 AM|LINK