Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
The Microsoft Office Access database engine could not find the object 'Sheet1$'.  Make sure the object exists and that you spell its name and the path name correctly.



What I have tried:

protected void Button1_Click(object sender, EventArgs e)
{
String strConnection = @"Data Source=PARAMERP4-PC\SPEEDPEQ;Initial Catalog=XYZ;Integrated Security=True";
//file upload path
string path = FileUpload12.PostedFile.FileName;
//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";
//Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [CLIENT],[TASK],[DESCRIPTION],[DATE],[TIME TAKEN],[CALL ATTENDED BY],[ISSUE RESOLVED BY],[Help By] from [Sheet1$]", excelConnection);
excelConnection.Open();
OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
//Give your Destination table name
sqlBulk.DestinationTableName = "Export_Excell_Sheet";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();
}





Excell collumn name :----CLIENT TASK, DESCRIPTION, DATE, TIME TAKEN, CALL, ATTENDED BY, ISSUE RESOLVED BY, Help By




Data Base Column name :--tbale name -Export_Excell_Sheet

[Export_Excell_Sheet]
(
[CLIENT] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TASK] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DESCRIPTION] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DATE] [datetime] NULL,
[TIME_TAKEN] [datetime] NULL,
[CALL_ATTENDED_BY] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ISSUE_RESOLVED_BY] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Help_By] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
Posted
Updated 15-Apr-16 21:29pm
Comments
ZurdoDev 15-Apr-16 8:49am    
Does your workbook have a sheet named "Sheet1?"

C#
private void ImporttoSQL(string sPath)
      {
          string sSourceConstr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", sPath);
          string sDestConstr = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
          OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
          using (sSourceConnection)
          {
              string sql = string.Format("Select * FROM [{0}]", "Sheet1$");
              OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
              sSourceConnection.Open();
              using (OleDbDataReader dr = command.ExecuteReader())
              {
                  using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sDestConstr))
                  {
                      bulkCopy.DestinationTableName = "Alh_portal";
                      bulkCopy.WriteToServer(dr);
                  }
              }
          }
      }
 
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