Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Professional

there is a case where i need to import data from Excel sheet to Sql server 2008 data base
i tried on google also got so closed coding structures also implemented but still its need to troubleshoot.

still the exception that is occurring is :-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.

and one thing that is really you need to aware that i am using Microsoft Enterprise Library
in ma project...

any appreciation is welcomed but without other website's link (specially if you yourself not practiced on that)...


Thanks in Advance
Posted
Comments
Maciej Los 28-Nov-13 2:08am    
Share your code. Without it we can't help you.
Shubh Agrahari 28-Nov-13 3:00am    
string connString = "";
//string FileName = Path.GetFileName();
string strFileType = Path.GetExtension(fileuploadExcel.FileName).ToLower();
//string path = fileuploadExcel.PostedFile.FileName;
string path = Server.MapPath(fileuploadExcel.FileName);
var fileName = string.Format("{0}\\" + path + "", Directory.GetCurrentDirectory());
//Connection String to Excel Workbook
if (strFileType.Trim() == ".xls")
{
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
string query1 = "select [AppliedDistrictName],[ChalanNo],[MobileNoForApp],[ApplicantName],[FatherName],[MobileNo],[PermDistrict],[TempDistrict] from [Sheet1$]";
string query = "SELECT * FROM [" + path + "$]";
OleDbConnection conn = new OleDbConnection(connString);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbCommand cmd = new OleDbCommand(query1, conn);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();

da.Fill(ds);
grvExcelData.DataSource = ds.Tables[0];
grvExcelData.DataBind();
da.Dispose();
conn.Close();
conn.Dispose();

Hi! See this Article. I hope it will help you. Thank You.
 
Share this answer
 
i had a same error before couple of days...

Please Make sure that path you are passing is the same path from were you are browse the file...
 
Share this answer
 
v2
Comments
Shubh Agrahari 29-Nov-13 6:45am    
Thanks buddy i done it with some troubleshoot
Rahul JR 29-Nov-13 6:59am    
welcome..
Thanks to you all and all your opinions.........

i solved it myselfy
 
Share this answer
 
Comments
Nelek 29-Nov-13 7:36am    
You should use the "improve solution" and add more information about how did you solve it, it can help other people having similar problems in the future.

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