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();
}
2

1 Answer 1

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$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.