可能重复:
填充数据表时,数据读取器是否比数据集更快?
public DataTable GetReviewsId(Objects myObjects)
{
DataTable tblBindReviews = new DataTable();
string Query = "";
try
{
Query = "select distinct ProductId from tblReview where ProductId in (select ProductId from tblProduct where R=0 and T=0)";
/*SqlConnection mySqlConnection = this.SetDatabaseConnection();
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(Query, mySqlConnection);
mySqlDataAdapter.Fill(tblBindReviews);*/
/*mySqlConnection.Open();
SqlCommand cmd = new SqlCommand(Query,mySqlConnection);
tblBindReviews.Load(cmd.ExecuteReader());*/
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
finally
{
this.ClosedatabaseConnection();
}
return tblBindReviews;
}
在上面的代码中,我编写了两种检索数据的方法(每种都在注释部分内),一种使用数据适配器,另一种使用数据读取器。两者中哪一个会跑得更快?