可能重複:
Is datareader quicker than dataset when populating a datatable?哪一個跑得快?
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;
}
在上面的代碼我寫使用數據適配器與其它兩種方式(各個評價部內)檢索數據的,一個使用datareader。哪一個會跑得更快?
爲什麼不嘗試一下自己之前加載? – sloth
您是否對您的樣本數據集進行了測試? 'System.Diagnostics.Stopwatch'是這些類型問題的朋友。 – jheddings
是什麼讓你覺得這兩種選擇之間還有區別? –