Hi:
I was trying to read data from an Excel file into a dataset. The file is retreived from a FileUpload. The below is my code and the error received. Please advice why it is occuring and how to fix it.
The Microsoft Jet database engine could not find the object 'fileName'. Make sure the object exists and that you spell its name and the path name correctly.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbExc
eption: The Microsoft Jet database engine could not find the object 'fileName'. Make sure the object exists and that you spell its name and the path name correctly.
Source Error:
Line 11657: DataSet ds = new DataSet();
Line 11658:
Line 11659: da.Fill(ds, "Employees");
Line 11660:
Line 11661: // Validate each column in this line.If error, reject the transaction. Else continue
[OleDbException (0x80040e37): The Microsoft Jet database engine could not find the object 'fileName'. Make sure the object exists and that you spell its name and the path name correctly.]
System.Data.OleDb.OleDbCom
mand.Execu
teCommandT
extForSing
leResult(t
agDBPARAMS
dbParams, Object& executeResult) +267
System.Data.OleDb.OleDbCom
mand.Execu
teCommandT
ext(Object
& executeResult) +192
System.Data.OleDb.OleDbCom
mand.Execu
teCommand(
CommandBeh
avior behavior, Object& executeResult) +48
System.Data.OleDb.OleDbCom
mand.Execu
teReaderIn
ternal(Com
mandBehavi
or behavior, String method) +106
System.Data.OleDb.OleDbCom
mand.Execu
teReader(C
ommandBeha
vior behavior) +111
System.Data.OleDb.OleDbCom
mand.Syste
m.Data.IDb
Command.Ex
ecuteReade
r(CommandB
ehavior behavior) +4
System.Data.Common.DbDataA
dapter.Fil
lInternal(
DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
System.Data.Common.DbDataA
dapter.Fil
l(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
System.Data.Common.DbDataA
dapter.Fil
l(DataSet dataSet, String srcTable) +83
genumd.TableEdit3.UploadFi
le(String fileName, String fileExtension, String filePath) in c:\Inetpub\wwwroot\genumd\
TableEdit3
.aspx.cs:1
1659
genumd.TableEdit3.btnDBUpl
oad_Click(
Object sender, EventArgs e) in c:\Inetpub\wwwroot\genumd\
TableEdit3
.aspx.cs:1
1612
System.Web.UI.WebControls.
Button.OnC
lick(Event
Args e) +105
System.Web.UI.WebControls.
Button.Rai
sePostBack
Event(Stri
ng eventArgument) +107
System.Web.UI.WebControls.
Button.Sys
tem.Web.UI
.IPostBack
EventHandl
er.RaisePo
stBackEven
t(String eventArgument) +7
System.Web.UI.Page.RaisePo
stBackEven
t(IPostBac
kEventHand
ler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePo
stBackEven
t(NameValu
eCollectio
n postData) +33
System.Web.UI.Page.Process
RequestMai
n(Boolean includeStagesBeforeAsyncPo
int, Boolean includeStagesAfterAsyncPoi
nt) +5102
Code:
protected void btnDBUpload_Click(object sender, System.EventArgs e)
{
string saveServDir = @"Uploads\"; // Server dir for storing uploaded csvs
string appPath = Request.PhysicalApplicatio
nPath;
if (brwUploadFile.HasFile)
{
string savePath = appPath + saveServDir + Server.HtmlEncode (brwUploadFile.FileName);
// Save file on server
brwUploadFile.SaveAs (savePath);
// Upload to database
UploadFile (brwUploadFile.PostedFile.
FileName, extension, savePath);
// Success...
lblDBUpload.Text = "Your file was uploaded successfully";
}
else
{
lblDBUpload.Text = "No file selected to upload";
}
}
//btnDBUpload_Click
/// Reads the file and uploads to the database if successfully validated.
/// Otherwise, write error to output file
protected void UploadFile(string fileName, string fileExtension, string filePath)
{
string connectionString;
string commandText;
System.Data.OleDb.OleDbCon
nection conn;
System.Data.OleDb.OleDbCom
mand command;
int count;
string strMsg;
connectionString = "Provider=Microsoft.Jet.OL
EDB.4.0;Da
ta Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=Yes'";
commandText = "select * from fileName";
conn = new System.Data.OleDb.OleDbCon
nection(co
nnectionSt
ring);
command = new System.Data.OleDb.OleDbCom
mand(comma
ndText, conn);
conn.Open();
System.Data.OleDb.OleDbDat
aAdapter da= new System.Data.OleDb.OleDbDat
aAdapter(c
ommandText
, conn);
DataSet ds = new DataSet();
da.Fill(ds, "MyData");
}
// UploadFile
Start Free Trial