我有 C# WinForms 应用程序,它从 Excel 工作表中获取信息并将其存储到我的数据库中,我的代码在我的 PC 上运行良好,但是当我更改它时出现错误
System.InvalidOperationException: 'Microsoft.ACE.OLEDB.12.0' 提供程序未在本地计算机上注册。
展示。我通过将项目平台从 x86 更改为 x64 解决了这个问题,但是当我使用 x64 启动项目时,我无法对许多文件收费,因此我必须在 x86 上运行它。大佬有什么解决办法吗?
Rq:我的代码:
String name = "Feuil1";
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
textBox_path.Text +
";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
DataTable data = new DataTable();
sda.Fill(data);
dataview1.DataSource = data;
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["UR2k_CS.Properties.Settings.StoreConnectionString"].ConnectionString))
{
String query = "INSERT INTO dbo.Stock (RFID,name,refrence,prix,Stockdate) VALUES (@RFID,@name,@refrence,@prix,@Stockdate)";
connection.Open();
for (int i=0;i<dataview1.Rows.Count-1;i++)
{
using (SqlCommand command = new SqlCommand(query, connection))
{
if ((dataview1.Rows[i].Cells[0].Value.ToString()!=null)&&((!checkifexist(dataview1.Rows[i].Cells[0].Value.ToString()))) &&(dataview1.Rows[i].Cells[0].Value.ToString()!=""))
{
command.Parameters.AddWithValue("@RFID", dataview1.Rows[i].Cells[0].Value.ToString());
command.Parameters.AddWithValue("@name", dataview1.Rows[i].Cells[1].Value.ToString());
command.Parameters.AddWithValue("@refrence", dataview1.Rows[i].Cells[2].Value.ToString());
command.Parameters.AddWithValue("@prix", dataview1.Rows[i].Cells[3].Value.ToString());
command.Parameters.AddWithValue("@Stockdate", DateTime.Now);
command.ExecuteNonQuery();
}
}
}
connection.Close();
}
您需要从microsoft 下载(我认为这是正确的)下载 32 位驱动程序,但您可能遇到的困难是一台机器不能同时安装 64 位和 32 位版本。
使用EPPlus是一种更现代的方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句