S
SpaceMarine
hello,
in my DAL here is how i typically fetch a single DataTable (for biz
layer consumption):
SqlConnection conn = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("GetFoo", conn);
command.CommandType = CommandType.StoredProcedure;
//do it - dataset & adapter
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
return ds.Tables[0];
but recently i came across something that suggested using a
DataReader:
SqlConnection conn = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("GetFoo", conn);
command.CommandType = CommandType.StoredProcedure;
//do it - datareader
conn.Open();
SqlDataReader dr =
command.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
//closing DataReader auto-closes the Connection due to above
dr.Close();
return dt;
....the idea being that since DataReaders are faster, this would fetch
& fill a DataTable faster than using a SqlDataAdapter to fill a
DataSet.
any thoughts?
thanks!
sm
in my DAL here is how i typically fetch a single DataTable (for biz
layer consumption):
SqlConnection conn = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("GetFoo", conn);
command.CommandType = CommandType.StoredProcedure;
//do it - dataset & adapter
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds);
return ds.Tables[0];
but recently i came across something that suggested using a
DataReader:
SqlConnection conn = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("GetFoo", conn);
command.CommandType = CommandType.StoredProcedure;
//do it - datareader
conn.Open();
SqlDataReader dr =
command.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
//closing DataReader auto-closes the Connection due to above
dr.Close();
return dt;
....the idea being that since DataReaders are faster, this would fetch
& fill a DataTable faster than using a SqlDataAdapter to fill a
DataSet.
any thoughts?
thanks!
sm