C# Npgsql Prepare的问题

C# Npgsql Prepare的问题,c#,npgsql,C#,Npgsql,我正试图通过一个带有C#的应用程序将一行插入PostgreSQL。按照中显示的步骤,我尝试构建一个准备好的语句,以便在表中插入一行。我明白了: NpgsqlConnection conn = dbConn.getConnection(); conn.Open(); NpgsqlCommand query = new NpgsqlCommand("insert into table(c1, c2) values(:v1, :v2)", conn); query.Parameters.Add(new

我正试图通过一个带有C#的应用程序将一行插入PostgreSQL。按照中显示的步骤,我尝试构建一个准备好的语句,以便在表中插入一行。我明白了:

NpgsqlConnection conn = dbConn.getConnection();
conn.Open();
NpgsqlCommand query = new NpgsqlCommand("insert into table(c1, c2) values(:v1, :v2)", conn);
query.Parameters.Add(new NpgsqlParameter("v1", NpgsqlDbType.Varchar));
query.Parameters.Add(new NpgsqlParameter("v2", NpgsqlDbType.Text));
query.Prepare();
query.Parameters[0].Value = "something";
query.Parameters[1].Value = "else";
得到了这个错误:

ERROR: 42601: syntax error in or near «:»
有什么意见吗


提前感谢

这是我的工作应用程序,所以我知道它可以工作,如果它不让我知道的话

conn.Open();

NpgsqlCommand command = new NpgsqlCommand("DELETE from accounts where user_name = :value1", conn);

// Now add the parameter to the parameter collection of the command specifying its type.
command.Parameters.Add(new NpgsqlParameter("value1", NpgsqlDbType.Varchar));

//Now, add a value to it and later execute the command as usual.                
command.Parameters[0].Value = email;
command.ExecuteNonQuery();

conn.Close();

Uhu,你为什么有这样的答案:根本就没有?把它们取下来。可能需要在@v1、@v2(在查询和参数中)执行此操作,但不知道该连接器。正如示例所示。我会试试的,谢谢你介意用最新的Npgsql版本试试吗?如果不行,请告诉我。我当然会的,我会让你注意到的。谢谢,我刚意识到你需要一个准备。但是这个例子可能对你仍然有用