日期:2014-05-17  浏览次数:20449 次

把EXCEL里的数据导入到SQLSERVER数据库老出错啊,代码贴出来了
string StrCon;
  StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source" + Server.MapPath("ExcelFile/20120714164403943.xls") + ";Extended Properties= 'Excel 8.0;HDR=YES;IMEX=1';";
  OleDbConnection conn = new OleDbConnection(StrCon);
  OleDbDataAdapter myda = new OleDbDataAdapter("select * from[Data$]", StrCon);
  DataSet myds = new DataSet();
  myda.Fill(myds);
  GVRepairReport.DataSource = myds;
  GVRepairReport.DataBind();
老是找不到可安装的ISAM
各位大姐姐大哥哥们帮帮忙

------解决方案--------------------
文件路径正确吗?
StrCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + Server.MapPath("~/ExcelFile/20120714164403943.xls") + "';Extended Properties= 'Excel 8.0;HDR=YES;IMEX=1';";

Data Seource缺少=
------解决方案--------------------
粘贴个我现在用的给你看下
string mingchen = filename;
string filePath = Server.MapPath("~/UploadFile/" + wenjia + "/")+filename;//路径 

string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
OleDbConnection ExcelConn = new OleDbConnection(strCon);
try
{
string strCom = string.Format("SELECT * FROM [Sheet1$]");
ExcelConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, ExcelConn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "[Sheet1$]");
ExcelConn.Close();
return ds;
}
catch (Exception ex)
{
ExcelConn.Close();
return null;
}