Hi
I'm Developing an application which will get the Excel file from the user and save it in folder after that on button click it want to read the excel file data and store it in database.
It was accepting the file and save it in folder.But it throws following Error near
myConnection.Open();
Error:
No error message available, result code: E_FAIL(0x80004005).
Here is my Inserting Code
void insertDB()
{
string FileName = lblFileName.Text;
string Extension = Path.GetExtension(FileName);
string FolderPath =Server.MapPath(ConfigurationManager.AppSettings["FolderPath"]);
string conStr = "";
switch (Extension)
{
case ".xls":
conStr =ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
break;
case ".xlsx":
conStr =ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
break;
}
using (var context = new LQTransAgentSeaFreightRateDataContext())
{
string sql = string.Format("Select * FROM [{0}]", "Sheet1$");
using (var myConnection = new OleDbConnection(conStr))
using (var myCommand = new OleDbCommand(sql, myConnection))
{
myConnection.Open();
var myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
context.TB_TransAgentSeaFreightRates.InsertOnSubmit(new TB_TransAgentSeaFreightRate()
{
tASF_VCPOD = myReader.GetString(0),
tASF_VCPOL = myReader.GetString(1),
tASF_VCForwarder= myReader.GetString(2),
tASF_VCForwarderReference= myReader.GetString(3),
tASF_VCShippingLine= myReader.GetString(4),
tASF_VCContainerType= myReader.GetString(5),
tASF_VCContainerSize= myReader.GetString(6),
tASF_DTEValidFrom = Convert.ToDateTime( myReader.GetString(7)),
tASF_DTEValidTo = Convert.ToDateTime(myReader.GetString(8)),
tASF_NUBasicRate= mobjGenlib.ConvertLong( myReader.GetString(9)),
tASF_NUPAF = mobjGenlib.ConvertLong(myReader.GetString(10)),
tASF_NUCAF = mobjGenlib.ConvertLong(myReader.GetString(11)),
tASF_NUPSS = mobjGenlib.ConvertLong(myReader.GetString(12)),
tASF_NUTotalAmount =mobjGenlib.ConvertLong(myReader.GetString(13)),
tASF_NUFreeDays = mobjGenlib.ConvertLong(myReader.GetString(14)),
tASF_VCCreditDays = myReader.GetString(15),
tASF_VCNITDeposit = myReader.GetString(16),
tASF_NUIsActive=1,
tASF_mCMP_NUUniqueId=mobjGenlib.ConvertLong(TXTCompanyID.Text)
});
}
}
context.SubmitChanges();
}
}
Can any one Please Help me to resolve this.
Thanks in Advance