c# - 在 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...
}
解决方案
推荐阅读
- reactjs - 不变违规:在 es6 导入中使用 React-Dom renderToString() 时出错
- python - 为什么 Python linecache 会影响 traceback 模块,但不会影响常规 traceback?
- oozie - 是否可以在不指定 inputDir 和 outputDir 的情况下运行 Oozie Spark Action
- linux - 当我在命令行中时,如何判断 Docker 映像正在运行什么 Linux?
- r - 删除文档中的文本并将其替换为空格
- asp.net - ASP.NET - 如何使用实体框架进行内部连接
- c# - 某些文件上 Xamarin.Android 上的 UnauthorizedAccessException
- xml - 从 XML 文件的两个不同标签中获取值并使用 XSLT 连接提取的值
- c# - 在执行其他操作时观看文件
- c++ - 如果 Else 语句缩进重要与否?(C++)