首页 > 解决方案 > 在 Plesk 服务器上创建 ODBC 连接后,如何在我的 asp.net 代码中使用它?

问题描述

我正在将 Excel 文件的数据上传到 HTML 文件。它可以在我的计算机上运行,​​但是当我将文件上传到服务器时,我发现错误:“未注册 'Microsoft.ACE.OLEDB.12.0' 提供程序”。

服务器中的控制面板是 Plesk。我想我必须在那里创建一个 ODBC 连接,我做到了。如何在我的代码中使用它?下面的代码:

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            string path = Path.GetFileName(FileUpload1.FileName);
            path = path.Replace(" ", "");
            FileUpload1.SaveAs(Server.MapPath("~/ExcelFile/") + path);
            String ExcelPath = Server.MapPath("~/ExcelFile/") + path;
            OleDbConnection mycon = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0; Persist Security Info = False");
            mycon.Open();
            OleDbCommand cmd = new OleDbCommand("select * from [table$]", mycon);
            OleDbDataAdapter da = new OleDbDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            grd.DataSource = ds.Tables[0];
            grd.DataBind();
            mycon.Close();
            LabelBrowse.Visible = true;
            LabelBrowse.Text = "Excel file has been saved and table populated.";
            //some more stuff...
}

标签: c#asp.netodbc

解决方案


推荐阅读