JAYRAM

JAYRAM

  • NA
  • 272
  • 213.7k

error ....Import/Upload Excel Data to Asp.net Gridview in C#

Apr 4 2013 3:44 AM
i got error like ..........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.


Please correct my code
protected void btnSubmit_Click(object sender, EventArgs e)
{
string path = fileupload.PostedFile.FileName;
string strmail = string.Empty;
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
OleDbConnection objConn = new OleDbConnection(connectionString);
objConn.Open();
String strConString = "SELECT UserName,EmailId FROM [Sheet1$]";
//where date = CDate('" + DateTime.Today.ToShortDateString() + "')";
OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn);
// Create new OleDbDataAdapter that is used to build a DataSet
// based on the preceding SQL SELECT statement.
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
// Pass the Select command to the adapter.
objAdapter1.SelectCommand = objCmdSelect;
// Create new DataSet to hold information from the worksheet.
DataSet objDataset1 = new DataSet();
// Fill the DataSet with the information from the worksheet.
objAdapter1.Fill(objDataset1, "srr");
DataGrid1.DataSource = objDataset1;
DataGrid1.DataBind();
// Clean up objects.
objConn.Close();
}

}


Answers (3)