日期:2014-05-17  浏览次数:21881 次

SaveFileDialog 提示尝试读取或写入受保护的内存。这通常指示其他内存已损坏
private void ExportExcel()
        {
            DataTable dtVilationList = Grab.GetVilationList(guid.ToString());

            SaveFileDialog dlg = new SaveFileDialog()
            {
                Filter = "*.xls|*.xls",
                RestoreDirectory = true,
                FileName = DateTime.Now.ToString("yyyyMMddhhmmss")
            };
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string[] columns = new string[] {
                    "车牌","违规时间","违规行为","违规地点","罚款金额","扣分","异地办理费"
                };
                int i = 0;
                foreach (string c in columns)
                {
                    dtVilationList.Columns[i++].ColumnName = c;
                }
                CSD.Tools.DownExcel downExcel = new CSD.Tools.DownExcel();
                downExcel.Width(0, 16);
                downExcel.Width(1, 18);
                downExcel.Width(2, 35);
                downExcel.Width(3, 35);
                downExcel.Width(6, 16);
                downExcel.File(dtVilationList, dlg.FileName);
                MessageBox.Show("导出成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

第一次SaveFileDialog 是正常显示,并能保存,,再次点击导出Excel的话会报错误,
错误定位在,“ if (dlg.ShowDialog() == DialogResult.OK)”
错误信息:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
数据是从Access读取的