开发者

Problem with Npgsql Prepare

I'm trying to insert a row into a PostgreSQL through an application with C#. Following the steps showed in Npgsql project homepage, I tryied to build a prepared statement in order yo insert a row in the table. I got this:

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));
que开发者_JAVA技巧ry.Prepare();
query.Parameters[0].Value = "something";
query.Parameters[1].Value = "else";

And got this error:

ERROR: 42601: syntax error in or near «:»

Any opinion?

thanks in advance


This is from my working app so I know it works, if it does not let me know.

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜