c#查询Excel文件oledb IErrorInfo.GetDescription失败了
本文关键字:GetDescription 失败 IErrorInfo oledb 查询 Excel 文件 | 更新日期: 2023-09-27 18:03:41
在oledb中执行此查询时,我得到IErrorInfo错误,有人可以帮助我吗?
"Select [Indirizzo] from [Mappatura$] Where [Cliente]='"+ Cliente[0].ToString()+"' AND [Soc]='"+Cliente[1].ToString()+"'"
您正在使用反向访问符号("$"),这是导致问题的原因。看看这个链接:https://support.office.com/en us/article/access - 2007 -保留字和符号——e33eb3a9 - 8 baa - 4335 - 9 - f57 da237c63eabe?correlationid=05072bb5 da4f - 40 - d0 - 8664 dd50ad5dbb6b& ui = en-US& rs = en-US&广告=我们# __toc272229038
public DataTable GetDatas(string QueryString, string SheetName)
{
DataTable dt = new DataTable();
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.DataSet DtSet;
System.Data.OleDb.OleDbDataAdapter MyCommand;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + FileName + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1'");
MyCommand = new System.Data.OleDb.OleDbDataAdapter(QueryString, MyConnection);
MyCommand.TableMappings.Add("Table", SheetName);
DtSet = new System.Data.DataSet();
MyCommand.Fill(DtSet);
dt = DtSet.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return dt;
}