我的是 C# windows 应用程序。当我在本地机器上运行此应用程序时,它会出现以下错误:-“初始化字符串的格式不符合从索引 128 开始的规范”。
try
{
string path = System.IO.Path.GetFullPath("E:\\09-2013\\SalesRep\\Openleads.xlsx");
if (Path.GetExtension(path) == ".xls")
{
oledbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + path + "Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"");
}
else if (Path.GetExtension(path) == ".xlsx")
{
oledbConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=" + path + "Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
}
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand(); ;
OleDbDataAdapter oleda = new OleDbDataAdapter();
DataSet ds = new DataSet();
cmd.Connection = oledbConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM [Raw Data$]";
oleda = new OleDbDataAdapter(cmd);
oleda.Fill(ds, "dsSlno");
grvData.DataSource = ds.Tables["dsSlno"].DefaultView;
oleda = new OleDbDataAdapter(cmd);
oleda.Fill(ds);
grvData.DataSource = ds.Tables[1].DefaultView;
}
catch (Exception ex)
{
}
finally
{
oledbConn.Close();
}