2

enter image description here

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();
}
eglease
  • 2,445
  • 11
  • 18
  • 28
kaziveh
  • 57
  • 8
  • 1
    Does this answer your question? ['Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine](https://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine) – Yong Shun Sep 12 '21 at 06:49
  • hi @YongShun when i run the project with local ip i got thi error but when i run it in visual my dataset i null or the table is not found – kaziveh Sep 12 '21 at 08:04

1 Answers1

1

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$

Ketan Kotak
  • 942
  • 10
  • 18