I am uploading the data of an Excel file to an HTML file. It works in my computer, but when I upload the files to the server, I find the error: "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered".
The control panel in the server is Plesk. I guess I have to create a ODBC connection there, and I did it. How to use it in my code? Code below:
protected void btnUpload_Click(object sender, EventArgs e)
{
string path = Path.GetFileName(FileUpload1.FileName);
path = path.Replace(" ", "");
FileUpload1.SaveAs(Server.MapPath("~/ExcelFile/") + path);
String ExcelPath = Server.MapPath("~/ExcelFile/") + path;
OleDbConnection mycon = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0; Persist Security Info = False");
mycon.Open();
OleDbCommand cmd = new OleDbCommand("select * from [table$]", mycon);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
grd.DataSource = ds.Tables[0];
grd.DataBind();
mycon.Close();
LabelBrowse.Visible = true;
LabelBrowse.Text = "Excel file has been saved and table populated.";
//some more stuff...
}