我有一个代码来调试我试图在 Excel 中导出数据的位置。它适用于较小的数据,但是当数据大小增加到数千时,我得到“内存不足异常”。我的应用程序在 IIS 6.0 上运行。有什么建议吗?
PS:进程通常在占用超过 1.2 GB 内存时会失败(查看任务管理器)
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
If (IsExportToCSV) Then
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.ContentType = "a"
'Remove the charset from the Content-Type header.
Response.Charset = ""
'Turn off the view state.
Page.EnableViewState = False
Dim tw As System.IO.StringWriter
tw = New System.IO.StringWriter
Dim hw As HtmlTextWriter = New HtmlTextWriter(tw)
'Get the HTML for the control.
Me.GridView1.AllowPaging = False
Me.GridView1.DataBind()
Me.GridView1.EnableViewState = False
Me.GridView1.AutoGenerateEditButton = False
Me.GridView1.RenderControl(hw)
Response.Write(tw.ToString)
Response.Flush()
Response.End()
Else
MyBase.Render(writer)
End If
End Sub