Hi all,
Which of the following is correct? Is there a better way to make it more to save resources?
The first version:
public static DataTable ExecuteGetTable(string connstring) {
using (SqlConnection connection=new SqlConnection(connstring))
SqlCommand command = new SqlCommand(connstring);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
}
The second version:
public static DataTable ExecuteGetTable(string connstring) {
using (SqlConnection connection=new SqlConnection(connstring))
using (SqlCommand command = new SqlCommand(connstring))
using (SqlDataAdapter adapter = new SqlDataAdapter())
adapter.SelectCommand = command;
return ds.Tables[0];
}
Thanks.