导出Excel文件不成功

CN001 2008-11-19 05:16:18
当查询语句返回结果数据少时,一切工作正常。但当返回结果大于一定数目(一千条以上,远没到65536)时就报错。错误信息如下:
无法从数据库中提取数据。
请检查数据库服务器或联系您的数据库管理员。确认外部数据库有效,然后重试该操作。

弄了一天,都快疯了,也没找到原因。望高手们赐教!
private void btnExportExcel_Click(object sender, EventArgs e)
{
ExcelExport("select * from tmp where rownum<1000", "示例");
}

public void ExcelExport(string 查询语句, string 标题)
{
Excel.Application excel;
Excel._Workbook xBk;
Excel._Worksheet xSt;
Excel._QueryTable xQt;
string Conn = "OLEDB;Provider=OraOLEDB.Oracle;Data Source=***;User ID=***;Password=***";
string Select = 查询语句;
excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
xBk = excel.Workbooks.Add(true);
xSt = (Microsoft.Office.Interop.Excel._Worksheet)xBk.ActiveSheet;
excel.Cells[2, 2] = 标题;
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Bold = true;
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Name = "黑体";
xSt.get_Range(excel.Cells[2, 2], excel.Cells[2, 2]).Font.Size = 22;
xQt = xSt.QueryTables.Add(Conn, xSt.get_Range("B4", Type.Missing), Select);
xQt.Name = "QueryTableName";
xQt.FieldNames = true;//显示字段名
xQt.RowNumbers = false;
xQt.FillAdjacentFormulas = false;
xQt.PreserveFormatting = false;
xQt.BackgroundQuery = true;
xQt.RefreshStyle = Microsoft.Office.Interop.Excel.XlCellInsertionMode.xlInsertDeleteCells;
xQt.AdjustColumnWidth = true;
xQt.RefreshPeriod = 0;
xQt.PreserveColumnInfo = true;
xQt.Refresh(xQt.BackgroundQuery);
excel.Visible = true;
}
...全文
221 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CN001 2008-11-20
  • 打赏
  • 举报
回复
看来求人不如求已啊.已解决
CN001 2008-11-19
  • 打赏
  • 举报
回复
看来没有引起专家们的关注.自己顶一下

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧