没有错误消息,结果代码:E_FAIL(0x80004005) [英] No error message available, result code: E_FAIL(0x80004005)

查看:213
本文介绍了没有错误消息,结果代码:E_FAIL(0x80004005)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发一个应用程序,它将从用户那里获取excel文件,并将读取excel中的数据,最后它将它绑定到网格视图。 />


我能够获取excel文件并将其存储在文件夹中,但是当我尝试打开文件时会抛出错误,因为

< b>无错误信息,结果代码:E_FAIL(0x80004005)到达 conn.open



这是我的代码:



Hi
I'm developing an application which will get the excel file from the user and will read the data in excel and finally it will bind it to grid view.

I'm able to get the excel file and store it in folder but when i try to open the file it throws an error as
"No error message available, result code: E_FAIL(0x80004005)" when reaches "conn.open"

Here is my code:

protected void btnSave_Click(object sender, EventArgs e)
        {
            string FileName = lblFileName.Text;
            string Extension = Path.GetExtension(FileName);
            string FolderPath = Server.MapPath(ConfigurationManager.AppSettings["FolderPath"]);
            string CommandText = "";
            switch (Extension)
            {
                case ".xls": //Excel 97-03
                    CommandText = "spx_ImportFromExcel03";
                    break;
                case ".xlsx": //Excel 07
                    CommandText = "spx_ImportFromExcel07";
                    break;
            }
string connString = "";
            //Connection String to Excel Workbook
            if (Extension.Trim() == ".xls")
            {
                connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FolderPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
            }
            else if (Extension.Trim() == ".xlsx")
            {
                connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FolderPath + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
            }
            string sheetvalue = ddlSheets.SelectedValue;
            string query = ("SELECT * FROM "  + sheetvalue ) ;
            OleDbConnection conn = new OleDbConnection(connString);
            if (conn.State == ConnectionState.Closed)
                conn.Open();
            OleDbCommand cmd = new OleDbCommand(query, conn);
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dg_AgentSFR.DataSource = ds.Tables[0];
            dg_AgentSFR.DataBind();
            da.Dispose();
            conn.Close();
            conn.Dispose();
}





请帮帮我。



谢谢提前。



Please Help me.

Thanks in advance.

推荐答案

Hi sorry in my connection string i have given the folder path and failed to give filename. 

Now the below code works for me 

connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FolderPath + FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";


这篇关于没有错误消息,结果代码:E_FAIL(0x80004005)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆