Reputation: 3
I'm attempting to use Npgsql parametrized queries in FSharp but I am unable to properly get Npgsql to update the parameter value. Sample code looks as follows:
let ins_command = new NpgsqlCommand("SELECT * FROM test_table WHERE keyid = :keyid")
ins_command.Parameters.Add(new NpgsqlParameter("keyid", NpgsqlTypes.NpgsqlDbType.Integer)) |> ignore
for key in keys do
ins_command.Parameters.["keyid"].Value = (box key)
ins_command.ExecuteScalar())
The "keyid" parameter is always set to null and when viewed as a watch variable it's never set. Without using AddWithValue
how can I set these parameters properly in FSharp?
Upvotes: 0
Views: 537
Reputation: 6223
I don't know the library, but the line
ins_command.Parameters.["keyid"].Value = (box key)
looks like it is doing nothing. Unless the =
operator has been changed, this is only a test for equality. It should give a compiler warning, as a check for equality is of type bool
and this line doesn't do anything with the result.
If you want to use a property setter (or assign to a mutable value), use the operator <-
Upvotes: 2