将excel导入到sql中报错:找不到可安装的 ISAM。 !!!谁帮帮我啊》?
代码如下:
string fullfilename = this.FileUpload1.PostedFile.FileName;
string filename = fullfilename.Substring(fullfilename.LastIndexOf("\\") + 1);
string type=fullfilename.Substring(fullfilename.LastIndexOf(".")+1);
if(type!="xls" || filename!="数据库文件.xls")
{
Jscript.Alert("您选择的文件不正确!");
}
else
{
string mystring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + fullfilename + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
DataSet myDs = new DataSet();
myDa.Fill(myDs);/////////////////////////////////在这里报错!!!!! 报错:找不到可安装的 ISAM!!
if (myDs.Tables[0].Rows.Count > 0)
{
string strSql = "";
string CnnString = "Provider=SQLOLEDB;database=HSSTORE;server=(local);uid=sa;pwd=wwwwww";
OleDbConnection conn = new OleDbConnection(CnnString);
conn.Open();
OleDbCommand myCmd = null;
for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
{
strSql = "insert into A(A,B) values ('";
strSql += myDs.Tables[0].Rows[i].ItemArray[1].ToString() + "', '";
strSql += myDs.Tables[0].Rows[i].ItemArray[2].ToString() + "')";
try
{
myCmd = new OleDbCommand(strSql, conn);
myCmd.ExecuteNonQuery();
Jscript.Alert("数据导入成功!");
}
catch
{
Jscript.Alert("数据导入失败!");
}
}
conn.Close();
}
}
------解决方案--------------------
连接字符串错误 ,把mystring 打印出来看一下
------解决方案--------------------up