首页 新闻 会员 周边 捐助

C# 实现下载csv,数据太多,请求超时,求解决办法!!!急!!!

0
悬赏园豆:50 [已解决问题] 解决于 2012-05-29 11:14

RT
代码:

protected void btnReport_Click(object sender, EventArgs e)
    {
        IList<Member> StudentList = Search();
        string data = ExportCSV(StudentList);
        string temp = string.Format("attachment;filename={0}", DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv");
        Response.ClearHeaders();
        Response.AppendHeader("Content-disposition", temp);
        Response.HeaderEncoding = Encoding.GetEncoding("shift-jis");
        Response.ContentType = "application/octet-stream";
        Response.ContentEncoding = Encoding.GetEncoding("shift-jis");
        Response.Write(data);
        Response.Flush();
        Response.Close();
        IsReport = false;
    }

public string ExportCSV(IList<Member> list)
    {
        string data = "";
        data = "First name,Last name,DOB,Email,Phone number,Gender,Points,Rank,Address,Suburb,Postcode,School,Avatar Name,Username,Password,DataCreated,Activated status\n";
        foreach (Member tb in list)
        {

            data += "\"" + tb.FirstName + "\","
                    + "\"" + tb.LastName + "\","
                    + "\"" + tb.DateOfBirth + "\","
                    + "\"" + tb.Email + "\","
                    + "\"" + tb.PhoneNumber + "\","
                    + "\"" + (tb.Gender == "F" ? "Female" : (tb.Gender == "M" ? "Male" : "")) + "\","
                    + "\"" + tb.Points + "\","
                    + "\"" + (tb.Rank == null ? "" : tb.Rank.Name) + "\","
                    + "\"" + tb.Address + "\","
                    + "\"" + tb.Suburb + "\","
                    + "\"" + tb.Postcode + "\","
                    + "\"" + (tb.School == null ? "" : tb.School.Name) + "\","
                    + "\"" + tb.Nickname + "\","
                    + "\"" + tb.Username + "\","
                    + "\"" + tb.Password + "\","
                    + "\"" + tb.DateCreated + "\","
                    + "\"" + tb.IsActive + "\","
                 + "\n";
        }
        return data;
    }
魔GUI的主页 魔GUI | 初学一级 | 园豆:139
提问于:2012-05-29 10:13
< >
分享
最佳答案
0

foreach循环里面用StringBuilder拼装字符串

StringBuilder很好用 还省内存

收获园豆:50
baixiujie | 菜鸟二级 |园豆:252 | 2012-05-29 11:12
其他回答(3)
0

数据库的话用DATAREADER一条条的写进WEB页面中..不要写进LIST中

56180825 | 园豆:1749 (小虾三级) | 2012-05-29 10:32

没用到Datareader,用的Nhibernate。

支持(0) 反对(0) 魔GUI | 园豆:139 (初学一级) | 2012-05-29 11:16
1

在web.config中设置一下请求超时设置:

<httpRuntime executionTimeout="300"/>

单位是秒,默认是110秒。

dudu | 园豆:29732 (高人七级) | 2012-05-29 10:36

非常感谢~已经设置过了,虽说能起作用,但是还是时间超长。

支持(0) 反对(0) 魔GUI | 园豆:139 (初学一级) | 2012-05-29 11:17
0
<httpRuntime executionTimeout="90" maxRequestLength="800000" useFullyQualifiedRedirectUrl="false"/>
maxRequestLength:设置最大请求的大小,单位:KB
executionTimeout:设置asp.net超时时间,单位:S(秒)
起个昵称真难 | 园豆:202 (菜鸟二级) | 2012-05-29 11:00

非常感谢~同1楼。

支持(0) 反对(0) 魔GUI | 园豆:139 (初学一级) | 2012-05-29 11:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册