我不知道我错在哪里。
当我使用本地机器程序成功运行时。 但是当我在服务器上传时,会出现像' Microsoft.ACE.OLEDB.12.0'提供商未在本地计算机上注册
protected void btnImport_Click(object sender, EventArgs e)
{
// try{
string connectionstring = "";
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string fileextension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string filelocation = Server.MapPath("~/file/") + filename;
FileUpload1.SaveAs(filelocation);
if (fileextension == ".xlsx")
{
connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filelocation + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=2\"";
OleDbConnection conn = new OleDbConnection(connectionstring);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "select * from [Sheet1$]";
cmd.Connection = conn;
OleDbDataAdapter oda = new OleDbDataAdapter(cmd);
System.Data.DataTable dt = new System.Data.DataTable();
oda.Fill(dt);
grvExcelData.DataSource = dt;
Session["TaskTable"] = dt;
grvExcelData.DataBind();
}
// }catch(Exception ex){Response.Write(ex.Message); }
}
错误图片