BigInt problem in PgSqlCommand
Posted: Fri 12 Sep 2014 15:03
I tried a very similar code like the code below:
long oid = 5123456789;
PgSqlCommand cmd = new PgSqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select id from table_a where oid = :OID";
cmd.Parameters.Clear();
cmd.Parameters.Add("OID", PgSqlType.BigInt);
cmd.Parameters["OID"].Value = oid;
object tmp = cmd.ExecuteScalar();
The connection is a working connection, that's sure. The problem is that I get an OverflowException when executing the last line with ExecuteScalar(). More details about the exception: "The value for Int32 was too big or too small".
I found out that the driver had problems to build the command. It seems that there is a problem to put the value 5123456789 into a bigint.
What is wrong here?
My workaround for now: When I don't use parameters, it works:
cmd.CommandText = "select id from table_a where oid = " + oid;
long oid = 5123456789;
PgSqlCommand cmd = new PgSqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select id from table_a where oid = :OID";
cmd.Parameters.Clear();
cmd.Parameters.Add("OID", PgSqlType.BigInt);
cmd.Parameters["OID"].Value = oid;
object tmp = cmd.ExecuteScalar();
The connection is a working connection, that's sure. The problem is that I get an OverflowException when executing the last line with ExecuteScalar(). More details about the exception: "The value for Int32 was too big or too small".
I found out that the driver had problems to build the command. It seems that there is a problem to put the value 5123456789 into a bigint.
What is wrong here?
My workaround for now: When I don't use parameters, it works:
cmd.CommandText = "select id from table_a where oid = " + oid;