当前位置:Gxlcms >
数据库问题 >
Microsoft.Jet.OLEDB.4.0 导入excel报"找不到可安装的ISAM"
Microsoft.Jet.OLEDB.4.0 导入excel报"找不到可安装的ISAM"
时间:2021-07-01 10:21:17
帮助过:5人阅读
connstring =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileName +
";Extended Properties=Excel 8.0;;HDR=YES;IMEX=1";
using (OleDbConnection conn =
new OleDbConnection(connstring))
{
conn.Open();
DataTable sheetsName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new Object[] {
null,
null,
null,
"TABLE" });
//得到所有sheet的名字
string firstSheetName = sheetsName.Rows[
0][
2].ToString();
//得到第一个sheet的名字
string sql =
string.Format(
"SELECT * FROM [{0}]", firstSheetName);
//查询字符串
//string sql = string.Format("SELECT * FROM [{0}] WHERE [日期] is not null", firstSheetName); //查询字符串
OleDbDataAdapter ada =
new OleDbDataAdapter(sql, connstring);
DataSet set =
new DataSet();
ada.Fill(set);
return set.Tables[
0];
}
将上述代码中
connstring = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + ";Extended Properties=Excel 8.0;;HDR=YES;IMEX=1
加上单引号,如下,即可解决问题。
connstring = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + fileName + ";Extended Properties=‘Excel 8.0;;HDR=YES;IMEX=1‘";
Microsoft.Jet.OLEDB.4.0 导入excel报"找不到可安装的ISAM"
标签:查询 ide ring from soft turn not 第一个 sts