我正在一个asp.net c#应用程序上与Postgresql连接。我有Windows 7 32位的PC。 首先,我在PC上安装了Postgresql版本 postgresql-10.14-1-windows 。然后我试图从C#窗口应用程序将数据插入到postgresql中。为此,我在项目中添加了“ Npgsql.dll”和“ System.ValueTuple.dll”的引用,并尝试了以下代码
var cs = "Host=localhost;Username=testuser;Password=test12345;Database=test;";
using (NpgsqlConnection connection = new NpgsqlConnection(cs))
{
//connection.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString();
//connection.ConnectionString = cs;
connection.Open();
NpgsqlCommand cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "Insert into employee values(@ID,@Fname,@Lname,@Email)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new NpgsqlParameter("@ID", Convert.ToInt32(txtEmpID.Text)));
cmd.Parameters.Add(new NpgsqlParameter("@EmpName", txtEmpName.Text));
cmd.Parameters.Add(new NpgsqlParameter("@Email", txtEmpEmail.Text));
cmd.Parameters.Add(new NpgsqlParameter("@Phone", txtEmpPhone.Text));
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
txtEmpEmail.Text = "";
txtEmpName.Text = "";
txtEmpID.Text = "";
txtEmpPhone.Text = "";
lblmsg.Text = "Data Has been Saved";
}
但是当我尝试运行它时会提示错误
{"Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.ValueTuple, Version=4.0.3.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"}
位置
using (NpgsqlConnection connection = new NpgsqlConnection(cs))
我尝试了很多解决方法,但是我对Postgresql还是很陌生,无法找到解决方案。请在这里帮助我。