Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got the error as 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.

MY CODE IS:

C#
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace samp
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnSend_click(object sender, EventArgs e)
        {
            String strConnection = "Data Source=MANIADSBHI-PC;Initial Catalog=master;Integrated Security=True";
            //file upload path
            string path = fileuploadExcel.PostedFile.FileName;
            //Create connection string to Excel work book
            string excelConnectionString = @"Provider=Microsoft.JET.OLEDB.4.0;Data Source=D:sampledata2003.xls;Extended Properties=Excel 8.0;Persist Security Info=False";
            //Create Connection to Excel work book
            OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
            excelConnection.Open();
            //Create OleDbCommand to fetch data from Excel

            OleDbCommand cmd = new OleDbCommand("Select * from  [sheet1$]", excelConnection);
            OleDbDataReader da= cmd.ExecuteReader(); 
             
            SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
           // Give your Destination table name
            sqlBulk.DestinationTableName = "emp";
            sqlBulk.WriteToServer(da);
            excelConnection.Close();
        }
    }
} 


Pls anyone help me in this error, i got the error on line no:31,32
OleDbCommand cmd = new OleDbCommand("Select * from [sheet1$]", excelConnection);
OleDbDataReader da= cmd.ExecuteReader();
Posted
Updated 8-Jun-14 23:56pm
v2

1 solution

you are providing that data source

Data Source=D:sampledata2003.xls


it is not correct,
if you want to give your local drive path than give like this

c:\\D:sampledata2003.xls


else you can set filename from fileupload also

C#
string path = fileuploadExcel.PostedFile.FileName;
          //Create connection string to Excel work book
          string excelConnectionString = @"Provider=Microsoft.JET.OLEDB.4.0;Data Source="+path+";Extended Properties=Excel 8.0;Persist Security Info=False";
 
Share this answer
 
v2
Comments
Member 10463904 9-Jun-14 6:29am    
now im getting this error..
The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.
line of :
excelConnection.Open();
Nirav Prabtani 9-Jun-14 6:33am    
try this solution

http://www.aspdotnet-suresh.com/2013/01/c-microsoft-office-access-database.html

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