+ -
当前位置:首页 → 问答吧 → Excel数据写入到数据库中出现异常“找不到可安装的 isam”

Excel数据写入到数据库中出现异常“找不到可安装的 isam”

时间:2011-12-17

来源:互联网

string mystring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\20111217.xls;Extended Properties='Excel 11.0;HDR=Yes;IMEX=1'";
  OleDbConnection cnnxls = new OleDbConnection(mystring);
  cnnxls.Open();
  OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [20111217$]", cnnxls);
  DataSet myDs = new DataSet();
  myDa.Fill(myDs);
  if (myDs.Tables[0].Rows.Count > 0)
  {
  for (int i = 1; i < myDs.Tables[0].Rows.Count; i++)
  {
  string iD = myDs.Tables[0].Rows[i].ItemArray[0].ToString();
  string Item_Code = myDs.Tables[0].Rows[i].ItemArray[1].ToString();
  string Item_Name = myDs.Tables[0].Rows[i].ItemArray[2].ToString();
  string planQuantity = myDs.Tables[0].Rows[i].ItemArray[3].ToString();
  string iPrice = myDs.Tables[0].Rows[i].ItemArray[4].ToString();
  string Discount = myDs.Tables[0].Rows[i].ItemArray[5].ToString();
  string iSum = myDs.Tables[0].Rows[i].ItemArray[6].ToString();
  string Description = myDs.Tables[0].Rows[i].ItemArray[7].ToString();
  string IsClose = myDs.Tables[0].Rows[i].ItemArray[8].ToString();
  }
  }


到了这一句 cnnxls.Open()就会抛出异常,请各位大虾帮忙看看,在此谢过

作者: xu_diligent   发布时间: 2011-12-17

Properties='Excel 11.0;HDR=Yes;IMEX=1'
IMEX=1 后面加上分号试试 IMEX=1;

作者: orain   发布时间: 2011-12-17

连接字符串问题,你的excel是什么版本的?07以上版本的写法是
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES";。

作者: dalmeeme   发布时间: 2011-12-17

03、02、00用的是
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";

作者: dalmeeme   发布时间: 2011-12-17

以上方法都试了,还是不行哦,8.0时提示外部表不是预期的格式

作者: xu_diligent   发布时间: 2011-12-17

最后加;,另外不用单引号,用双引号,试试
string mystring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\20111217.xls;Extended Properties=""Excel 11.0;HDR=Yes;IMEX=1;""";
 

作者: dalmeeme   发布时间: 2011-12-17

嗨,还是不行哦,会不会有其它原因呢

作者: xu_diligent   发布时间: 2011-12-17

引用 7 楼 xu_diligent 的回复:

嗨,还是不行哦,会不会有其它原因呢

重装一下 MDAC 看看。

作者: orain   发布时间: 2011-12-17