错误“外部表不是预期的格式” [英] Error “External table is not in the expected format”

查看:66
本文介绍了错误“外部表不是预期的格式”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



here is my code

protected void btnSubmit_OnClick(object sender, EventArgs e)
    {
         string path = @"C:\Users\Mazen\Desktop\Source\Book1.xlsx";
         String strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
                                  + "Data Source=" + path + "; "
                                 + "Extended Properties='Excel 8.0;HDR=Yes'";

         OleDbConnection connExcel = new OleDbConnection(strExcelConn);
         OleDbCommand cmdExcel = new OleDbCommand();
         cmdExcel.Connection = connExcel;
         connExcel.Open();
         System.Data.DataTable dtExcelSchema;
         dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
         connExcel.Close();

         DataSet ds = new DataSet();
         string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
         cmdExcel.CommandText = "SELECT ID, Name From [" + SheetName + "]";
         OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
         da.SelectCommand = cmdExcel;
         da.Fill(ds);
}



它给出了一个错误如何解决它..如果我将Jet更改为ACE所以它给出了错误提供程序未在本地计算机上注册。请帮帮我


its give an error how to fix it.. If i changed Jet to ACE so its gives an error provider is not registered on the local machine. please help me

推荐答案

OleDb提供者不接受某些词,比如 Name 。这是一个保留字 [ ^ ]并且应该以 [] 括号为基础。



您的命令文本错误,原因是另一个原因:在工作表名称之后需要添加
OleDb provider does not accept some words, like Name. It is a reserved word[^] and should be arrounded with [] brackets.

Your Command text is wrong, because of another reason: after worksheet name it is needed to add


符号。请参阅: http://www.connectionstrings.com/microsoft-jet-ole-db -4-0 / [ ^ ]



最后,它应该是:

sign. Please, see: http://www.connectionstrings.com/microsoft-jet-ole-db-4-0/[^]

Finally, it should be:
mdExcel.CommandText = "SELECT ID, [Name] From [" + SheetName + "


;





;)



;)


这篇关于错误“外部表不是预期的格式”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆