导出“datareader”数据

时间:2012-01-16 18:49:16

标签: c# .net

我是这个网站的新手,但在这里找到非常有用的信息。我有一个问题,我将结果从一个sql 8 db返回到用C#编写的网站上的网格控件。结果非常大,我说的是800K行!几个月前,它一直很好用。我不确定管理员可能对我的内存资源做了什么。因此,现在我将报告限制为仅三个月的数据,但即使仍然需要大约20分钟(工作时)来检索任何数据。我也可以选择导出数据,因此我无法使用数据读取器来传输数据。在暂存环境中,一切正常,但在生产环境中却没有。我现在已经没想到了。 dba说它是一个应用问题,我说它是一个数据库问题。以下是代码示例:

// Get Data

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da;
DataSet ds = new DataSet();

con.ConnectionString = "MyConnectionString";
con.Open();

cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "MyStoredProc";
da = new SqlDataAdapter(cmd);
da.Fill(ds);

con.Close();

StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htw);

Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=Report.xls");
Response.Write(sw.ToString());
Response.End();

1 个答案:

答案 0 :(得分:0)

您可以在数据库或网站中超时。绝对要做一些性能调整,也许要查看一次只返回少量行的接口。

Excel表格上是否还有65k行限制?

相关问题