我正在使用NpgSQL与PostgreSQL和ADO.NET。请原谅我的问题很简单,因为我刚开始使用PostgreSQL和NpgSQL这个星期。
像下面这样的代码是可以正常工作的:
当我输入参数时,出现了以下错误信息: Npgsql.NpgsqlException:ERROR:42703:列“_firstname”不存在
像下面这样的代码是可以正常工作的:
[Test]
public void InsertNoParameters()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=localhost; Database=postgres; User ID=postgres; Password=password");
conn.Open();
IDbCommand command = conn.CreateCommand();
string sql = "INSERT INTO Customers (FirstName,LastName) VALUES ('Test','Tube')";
command.CommandText = sql;
command.ExecuteNonQuery();
conn.Close();
}
当我输入参数时,出现了以下错误信息: Npgsql.NpgsqlException:ERROR:42703:列“_firstname”不存在
[Test]
public void InsertWithParameters()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=localhost; Database=postgres; User ID=postgres; Password=password");
conn.Open();
IDbCommand command = conn.CreateCommand();
string sql = "INSERT INTO Customers (FirstName,LastName) VALUES (_FirstName,_LastName)";
command.CommandText = sql;
var parameter = command.CreateParameter();
parameter.ParameterName = "_FirstName";
parameter.Value = "Test";
command.Parameters.Add(parameter);
parameter = command.CreateParameter();
parameter.ParameterName = "_LastName";
parameter.Value = "Tube";
command.Parameters.Add(parameter);
command.ExecuteNonQuery();
conn.Close();
}