Re: OdbcCommand Parameter

Lists: pgsql-hackers-win32
From: "Luca Beretta" <luca(dot)beretta(at)dataelco(dot)it>
To: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: OdbcCommand Parameter
Date: 2004-09-22 07:31:05
Message-ID: 20040922073547.CEA09329D18@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers-win32

hi to all,
i'm using C# to write an application based on postgresql 8.0 beta 2 (win32),
and i'm experiencing a problem using .NET Framework OdbcCommand class:
i need to pass some OdbcParameter, but i don't know how kind of name i need
to use for pgsql SQL sentence; with MS SQL Server i call them @param1
@param2, ecc

but if i do this with pgsql odbc 7.05.00.02 i get this error

[OdbcException: ERROR [HY000] ERROR: operator does not exist: @@ character
varying]

i think it depends by parameters names, so tried @@param,$param,%param but i
get always
the same exception.

which is the right mode ?

thanks a lot


From: "Gary Doades" <gpd(at)gpdnet(dot)co(dot)uk>
To: <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: OdbcCommand Parameter
Date: 2004-09-22 17:45:56
Message-ID: 4151C864.18996.242E3F23@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers-win32

On 22 Sep 2004 at 9:31, Luca Beretta wrote:

> [OdbcException: ERROR [HY000] ERROR: operator does not exist: @@ character varying]
> i think it depends by parameters names, so tried @@param,$param,%param but i get always
> the same exception.
>
> which is the right mode ?

For ODBC the parameters are positional not named. For C# you would use something
like the following:

OdbcCommand cmd = new OdbcCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "{call LoadCustCliOrders(?,?,?,?)}";

cmd.Parameters.Add("CUST_ID",OdbcType.Int);
cmd.Parameters.Add("CLIENT_ID",OdbcType.Int);
cmd.Parameters.Add("DATE_FROM",OdbcType.Date);
cmd.Parameters.Add("DATE_TO",OdbcType.Date);

...

cmd.Parameters["CUST_ID"].Value = _CustId;
cmd.Parameters["CLIENT_ID"].Value = _ClientId;
cmd.Parameters["DATE_FROM"].Value = _DateFrom;
cmd.Parameters["DATE_TO"].Value = _DateTo;

cmd.ExecuteReader (or whatever)...

The names don't matter, you just need to make sure you have the parameters added
in the same order they appear in your SQL.

This is an example of calling a stored procedure, but the same general principle
applies to textual SQL statements.

If you need further examples, let me know.

Cheers,
Gary.