Re: OdbcConnection - parameter problem



With the OLE DB providers you need to build a matching Parameters
collection--one for each parameter marker (?) in the SQL. These are
positional (not named as they are in SqlClient) so they must be added to the
Parameters collection in the correct order.

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

"David Thielen" <thielen@xxxxxxxxxxxxx> wrote in message
news:EAB07CE2-CC69-4F10-8191-484F5FAE3C4B@xxxxxxxxxxxxxxxx
Apparently the trick is to use a ? in the select as:

cmd.CommandText = "select lastname from employees where (employeeid < 8)
and (lastname = ?)";

But how does it know what ? to sub for each parameter?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"David Thielen" wrote:

Hi;

I have an OdbcConnection (ADO.NET) to Sql Server (I know I can use the
SqlConnection - I'm testing our code when it uses ODBC) with:

protected DbProviderFactory provider;
protected DbCommand cmd;

...

cmd.CommandText = "select lastname from employees where (employeeid < 8)
and (lastname = @p0)";
DbParameter param = provider.CreateParameter();
param.ParameterName = "@p0";
param.Value = "thi";
cmd.Parameters.Add(param);
cmd.ExecuteReader();

And I get:
$exception {"ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL
Server]Must declare the variable '@p0'."} System.Exception
{System.Data.Odbc.OdbcException}

Any ideas? This works great for the SqlServerConnection.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




.



Relevant Pages

  • Re: ado vs oledb
    ... Most mainstream SQL databases have "native" .NET providers using managed ... attempting to use a generic OLEDB provider--if you care about performance. ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: ASP.net hosting?
    ... manager access to the SQL databases - you must go through their interface. ... problem for writing in database on web. ... writing data back to database. ... The one I have seen are poor and also alot of providers ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ADSI
    ... providers for the integration with web application, ... "Joe Kaplan" wrote: ... used in SQL. ... Co-author of "The .NET Developer's Guide to Directory Services Programming" ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: SqlDbType error message
    ... You should remove reference to System.Data.Common.dll as its functionality ... SQL Mobile providers. ... Files\Microsoft Visual Studio ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Apartment model OLEDB Provider
    ... > I've written an apartment model OLEDB provider that works fine with SQL ... I seem to recall having seen something about only in-process providers ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.data.oledb)