1

C# のアプリケーションを使用して PostgreSQL に行を挿入しようとしています。Npgsql プロジェクトのホームページ に示されている手順に従って、テーブルに行を挿入するために準備済みステートメントを作成しようとしました。私はこれを得た:

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 «:»

何か意見はありますか?

前もって感謝します

4

1 に答える 1

0

これは私の作業中のアプリからのものであるため、通知されない場合でも機能することはわかっています。

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();
于 2012-04-25T06:33:09.920 に答える