日期:2014-05-20  浏览次数:21283 次

Index was outside the bounds of the array
在将dataset中的数据导入到excel时出现错误:Index   was   outside   the   bounds   of   the   array
好象服务器上的缓存没能及时释放,请各位高手指教如何解决。

------解决方案--------------------
索引越界,这个与缓存没关系 看看出错处代码?
------解决方案--------------------
int[] myArr = new Arr[3]{1,2,3};
int test = Arr[5];//数组越界

应该是上面的原因吧,仔细检查一下数组。
------解决方案--------------------
一个只有3个元素的数组,你要去取第6个元素,当然会错啦!
------解决方案--------------------
把代码贴出来吧
------解决方案--------------------
public void ExportData(DataGrid ds,string attachName)
{
Response.Clear();
Response.Buffer= true;
Response.Charset= "utf-8 ";

Response.AppendHeader( "Content-Disposition ", "attachment; " + attachName + "=.xls ");
Response.ContentEncoding=System.Text.Encoding.GetEncoding( "utf-8 ");
//Response.ContentType指定文件类型 可以为application/ms-excel || application/ms-word || application/ms-txt || application/ms-html || 或其他浏览器可直接支持文档
Response.ContentType = "application/vnd.ms-excel ";
Response.Charset = " ";

//关闭 ViewState
EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();//将信息写入字符串
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);//在WEB窗体页上写出一系列连续的HTML特定字符和文本。
//此类提供ASP.NET服务器控件在将HTML内容呈现给客户端时所使用的格式化功能
//获取control的HTML
ds.RenderControl(hw);//将DATAGRID中的内容输出到HtmlTextWriter对象中
// 把HTML写回浏览器
Response.Write(tw.ToString());
Response.End();
}
------解决方案--------------------
数据量少了可以如几百条,多了如几千条就出问题
-------------------------
的确有这个问题!