ASP.NET将数据库导出到EXCEL问题!

yaoxiah 2008-06-04 11:19:12
在ASP.NET页面中,实现点击按钮,将数据库的表项导入EXCEL中。异常如下:

用户代码未处理 System.Runtime.InteropServices.COMException
Message="不能使用 '';文件已在使用中。"
Source="Microsoft JET Database Engine"
ErrorCode=-2147467259
StackTrace:
在 ADODB.ConnectionClass.Open(String ConnectionString, String UserID, String Password, Int32 Options)
在 简表2.Automation_ADORecordset() 位置 c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\网上申报系统\简表2.aspx.cs:行号 64
在 简表2.Button1_Click1(Object sender, EventArgs e) 位置 c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\网上申报系统\简表2.aspx.cs:行号 47
在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

用其他数据库文件没问题的。请各位高人救急!
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zpcoder 2008-06-05
  • 打赏
  • 举报
回复
他不是说了文件在使用吗?

可能你的某个

SqlDataReader DataSet 没有关


还有,你写错了。但没有把重要的提示贴出来
sxmonsy 2008-06-05
  • 打赏
  • 举报
回复
首先你在对Excel表操作的时候,要先关闭Excel不要对表进行操作,同时不要将Excel设为只读。
然后在程序里要及时关闭对Excel的操作连接。
yaoxiah 2008-06-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zpcoder 的回复:]
他不是说了文件在使用吗?

可能你的某个

SqlDataReader DataSet 没有关


还有,你写错了。但没有把重要的提示贴出来
[/Quote]


哪里写错了??
changjiangzhibin 2008-06-05
  • 打赏
  • 举报
回复
估计是有连接或什么资源打开后未关闭
yaoxiah 2008-06-05
  • 打赏
  • 举报
回复
谢谢大家!
的确是SqlDataReader没有关

现在又有一个问题 就是objConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_strNorthwind + ";", "", "", 0);
但是我连接的是SQLSERVER 不知道上面的句子该怎么写啊!我写了报错:



用户代码未处理 System.Runtime.InteropServices.COMException
Message="[DBNETLIB][ConnectionOpen (ParseConnectParams()).]无效的连接。"
Source="Microsoft OLE DB Provider for SQL Server"
ErrorCode=-2147467259
StackTrace:
在 ADODB.ConnectionClass.Open(String ConnectionString, String UserID, String Password, Int32 Options)
在 简表2.Automation_ADORecordset() 位置 c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\网上申报系统\简表2.aspx.cs:行号 69
在 简表2.Button1_Click1(Object sender, EventArgs e) 位置 c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\WebSites\网上申报系统\简表2.aspx.cs:行号 47
在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
帮帮忙啊……

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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