在我的MVC應用程序,我們需要一次加載超過10萬的紀錄,但在檢索量等我的瀏覽器中得到墜毀數據..如何在數據表中加載大量的數據?
下面是我的代碼
string sql = "SELECT * FROM DBO.MY_TEST_DATA";
//MSSQL CONNECTION STRING
string myCnString = "Data Source=MYIPSERVER;Initial Catalog=my_database;
Persist Security Info=True;User ID=sa;Password=myPwd";
DataTable dt = GetDataTable(myCnString, sql);
//Todo: Use the table data
public DataTable GetDataTable(string cnString, string sql)
{
using (SqlConnection cn = new SqlConnection(cnString))
{
cn.Open();
using (SqlDataAdapter da = new SqlDataAdapter(sql, cn))
{
da.SelectCommand.CommandTimeout = 120;
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
}
}
用戶不可能在頁面上吸收那麼多信息。使用服務器端分頁。 –
你爲什麼要這樣做?沒有人會看100000+數據行。如果你想轉讓他們提供他們作爲下載或Web服務。如果你想顯示數據只傳輸相關數據。 –
你試圖做的不是一個好習慣。查看分頁並將數據行一次一批地提供給客戶端(頁面大小)。您可以使用本機的ASP.NET數據網格,也可以使用jQuery DataTables等第三方數據網格。 –