Office中国论坛/Access中国论坛

标题: [转帖]关于excel-access [打印本页]

作者: 红枫叶    时间: 2006-3-31 14:12
标题: [转帖]关于excel-access
asp.net页面上一个BUTTON,点了之后将excel文件数据导入到access中

函数写的错在哪里了?

private void Button1_Click(object sender, System.EventArgs e)
  {
   string ConnStr="rovider=Microsoft.Jet.OLEDB.4.0;Data source="+Server.MapPath("test.mdb");  //数据库
   OleDbConnection oleConnection = new OleDbConnection(ConnStr);
   oleConnection .Open();
   this.Label1.Text="连接状态:" + oleConnection.State; //监测状态
   
   string query="SELECT * INTO NewContact FROM [Text;FMT=Delimited;HDR=Yes;DATABASE=D:\\project\\webexcel\\;].[Contacts#txt];";  

   IDbCommand idbCommand=oleConnection.CreateCommand();
   idbCommand.CommandText=query;
   idbCommand.ExecuteNonQuery();

   this.Label1.Text="操作成功";
   
  }

出错信息:

“/WebApplication1”应用程序中的服务器错误。
--------------------------------------------------------------------------------

在文本文件规范 'Contacts.txt' 中, Format 选项无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.OleDb.OleDbException: 在文本文件规范 'Contacts.txt' 中, Format 选项无效。

源错误:


行 82:    IDbCommand idbCommand=oleConnection.CreateCommand();
行 83:    idbCommand.CommandText=query;
行 84:    idbCommand.ExecuteNonQuery();
行 85:    this.Label1.Text="操作成功";
行 86:   


源文件: d:\project\webexcel\webaccess.aspx.cs    行: 84

堆栈跟踪:


[OleDbException (0x80004005): 在文本文件规范 'Contacts.txt' 中,  Format 选项无效。]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +67
   WebApplication1.WebAccess.Button1_Click(Object sender, EventArgs e) in d:\project\webexcel\webaccess.aspx.cs:84
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277
作者: wwwwa    时间: 2006-3-31 16:00
1、是EXCEL还是TXT文件?

2、如是EXCEL:

string query="SELECT * into T2 from [Excel 8.0;HDR=YES;DATABASE=c:\1.xls].[Sheet1$]"




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3