Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
void insertDB()
        {
            string FileName = lblFileName.Text;
            string Extension = Path.GetExtension(FileName);
            string FolderPath =Server.MapPath(ConfigurationManager.AppSettings["FolderPath"]);
            string conStr = "";
            switch (Extension)
            {
                case ".xls": //Excel 97-03
                conStr =ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
                break;
                case ".xlsx": //Excel 07
                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
Posted
Comments
Nirav Prabtani 21-Mar-14 3:08am    
Have you debug code???
[no name] 21-Mar-14 3:13am    
While Debugging it shows the same error

Error:

No error message available, result code: E_FAIL(0x80004005).
Maciej Los 21-Mar-14 3:31am    
What is stored in: ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString?
[no name] 21-Mar-14 3:37am    
It means

<pre lang="c#">add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'"/></pre>

Which is given in web.config file

1 solution

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