ASP.NET Webform中的Microsoft数据访问组件(MDAC)问题

我想在我的网站上上传一个excel文件,然后处理这些行并将行插入到我的microsoft sql服务器中。但是当上传excel文件时出现此错误:

The .Net Framework Data Providers require microsoft Data access Components(MDAC). Please install microsoft Data access Components(MDAC) version 2.6 or later.

这是我的代码:

        string FileUpload = null;
        if (FileUploadBTN.FileName.Length > 0)
        {
            string picPath = Server.MapPath(Request.ApplicationPath) + @"\Temporaryfiles\";
            FileUploadBTN.SaveAs(picPath + Path.GetFileName(FileUploadBTN.FileName));
            FileUpload = picPath + Path.GetFileName(FileUploadBTN.FileName);
        }
        try
        {
            string Extension = Path.GetExtension(FileUpload);
            string conStr = "";
            switch (Extension)
            {
                case ".xls":
                    conStr = @"Provider=microsoft.ACE.OLEDB.4.0;Data Source=" + FileUpload + ";Extended Properties='Excel 12.0;HDR=YES'";
                    break;
                case ".xlsx":
                    conStr = @"Provider=microsoft.ACE.OLEDB.12.0;Data Source=" + FileUpload + ";Extended Properties='Excel 12.0;HDR=YES'";
                    break;
            }
            OleDbConnection conn = new OleDbConnection(conStr);
            conn.Open();
            string query = "select * from [Sheet1$]";
            OleDbdataAdapter da = new OleDbdataAdapter(query,conn);
            DataSet ds = new DataSet();
            da.Fill(ds,"activities");
            conn.Close();
            DataTable ExcelData = ds.Tables["activities"];
            int counter = 0;
            SQLClass dbc = new SQLClass();
            using (TransactionScope scope = new TransactionScope())
            {
                foreach (DataRow row in ExcelData.Rows)
                {
                    //Some code
                }
                scope.Complete();
                File.Delete(FileUpload);
            }
        }
        catch(Exception err) { string m = err.Message; }

我给主机打了电话,他们说已经安装了2.8版的microsoft数据访问组件(MDAC)。

我的错误在哪里?

非常感谢。

wendy6923 回答:ASP.NET Webform中的Microsoft数据访问组件(MDAC)问题

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2636883.html

大家都在问