在我的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等第三方数据网格。 –