Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all,
I am importing excel file and binding to grid i am able to code in Vb.net and when I convert the code in c# the error occurs: "Microsoft.oledb. can't find the sheet1$".

Anyone knows the solution please let me know.

regards
bilal
Posted
Updated 12-Oct-10 7:45am
v3
Comments
TheyCallMeMrJames 12-Oct-10 14:27pm    
That error isn't likely exactly what you're seeing. Please update your question with a bit of code and the exact error message.
pronning300 13-Oct-10 12:14pm    
Code:
String sConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + file + ";" +
"Extended Properties=Excel 8.0;";


OleDbConnection objConn = new OleDbConnection(sConnectionString);

objConn.Open();

OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1]", objConn);

OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();

objAdapter1.SelectCommand = objCmdSelect;

DataSet objDataset1 = new DataSet();

objAdapter1.Fill(objDataset1);

objConn.Close();

Error:
The Microsoft Jet database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.

1 solution

this is the code
String connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=" + file + ";"
+ "Extended Properties='Excel 8.0;HDR=No'";
// string connString = ConfigurationManager.ConnectionStrings["xlsx"].ConnectionString;
OleDbConnection oledbConn = new OleDbConnection(connString);
// OleDbCommand cmdExcel = new OleDbCommand();



//Check if the Sheet Exists

oledbConn.Open();

// Create OleDbCommand object and select data from worksheet Sheet1

OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", oledbConn);

//Or Use OleDbCommand
DataSet ds = new DataSet();

if (da != null)
{
da.Fill(ds);
GridView1.DataSource = ds.Tables["ExcelInfo"].DefaultView;
GridView1.DataBind();
}



and the error is "Microsoft Office Access database engine Could not find the object Sheet1$"

please tell me the solution if u know
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900