I am reading the excel data when the excel file uploading and save the excel content in my db.
now i get this error , how to rectify this 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.
code:
else if (extn.Equals(".xls"))
{
string filePath = Server.MapPath("uploads/" + filename);
//string connstring = "Provider=Microsoft.ACE.OLEDB.
string connstring = "Provider=Microsoft.Jet.OLEDB.
//Extended Properties='Excel 8.0;HDR=NO;IMEX=1';"; //This connection string is appropriate for Office 2007 and the older version. We can select the most suitable connection string according to Office version or our program.
using(OleDbConnection conn = new OleDbConnection(connstring))
{
conn.Open();
DataTable sheetsName = conn.GetOleDbSchemaTable(
string firstSheetName = sheetsName.Rows[0][2].
string sql = string.Format("SELECT * FROM [$Sheet1],firstSheetName"); //Query String
OleDbDataAdapter ada =new OleDbDataAdapter(sql,
DataSet set = new DataSet();
ada.Fill(set);
//set.Tables[0];
}
query = @"INSERT INTO Fileupload([category],[subcategory],[uid],[oid],[up_name],[demo1],[keyword],[fdata],[aflag],sizebyte)
VALUES(@category,@subcategory,@uid,@oid,@up_name,@demo1,@keyword,@fdata,1,@sizebyte) ";
SqlCommand command = new SqlCommand(query, con);
//command.CommandText = command.CommandText.ToString();
command.Parameters.AddWithValue("@category", dropcategory.SelectedValue.ToString());
command.Parameters.AddWithValue("@subcategory", DropDownList1.SelectedValue.ToString());
command.Parameters.AddWithValue("@uid", Session["user_id"].ToString());
command.Parameters.AddWithValue("@oid", txtOwnerId.SelectedItem.ToString());
command.Parameters.AddWithValue("@up_name", fname);
command.Parameters.AddWithValue("@demo1", demo1.Text);
command.Parameters.AddWithValue("@keyword", key);
command.Parameters.AddWithValue("@fdata", );
command.Parameters.AddWithValue("@sizebyte", size);
command.ExecuteNonQuery();
}
George ericPosted Jul 17, 2012, 4:04 AM
I also want to add that Excel is a database (technically) , worksheet is a datatable.
sudharsan sPosted Jul 13, 2012, 7:45 AM
if i have 3 sheets in one excel . how can i read all the three sheets data ?
help me...!
George ericPosted Jul 13, 2012, 4:53 AM
Read Excel Oledb
1,http://csharp.net-informations.com/excel/csharp-excel-oledb.htm
2. http://www.codeproject.com/Articles/198572/Summarize-C-Control-Excel-Skills