这是我的代码
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
string path = @"C:\Users\Mazen\Desktop\Source\Book1.xlsx";
String strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=" + path + "; "
+ "Extended Properties='Excel 8.0;HDR=Yes'";
OleDbConnection connExcel = new OleDbConnection(strExcelConn);
OleDbCommand cmdExcel = new OleDbCommand();
cmdExcel.Connection = connExcel;
connExcel.Open();
System.Data.DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
connExcel.Close();
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
cmdExcel.CommandText = "SELECT ID, Name From [" + SheetName + "]";
OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter();
da.SelectCommand = cmdExcel;
da.Fill(ds);
}
它给出了一个错误如何解决它..如果我改变Jet到ACE所以它给出了一个错误 提供程序未在本地计算机上注册。请帮帮我
答案 0 :(得分:1)
请尝试以下strExcelConn
:
String strExcelConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";