protected void btnUpload_Click(object sender, EventArgs e)
{
string query = "SELECT * FROM [Sheet$]";
OleDbConnection conn = new OleDbConnection(ConStr);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
OleDbCommand cmd = new OleDbCommand(query, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
You need to install Microsoft Access Database Engine. It varies from office version.
https://www.microsoft.com/en-in/download/details.aspx?id=13255
or
https://www.microsoft.com/en-us/download/details.aspx?id=54920
for this OLEDB error
and now your null problem can be due to Sheet$ not exist in your workbook. You need to make sure your excel has the same name of tab. like if your excel has table Sheet1, Sheet2 you can get data with Sheet1$ and Sheet2$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.