Re: OdbcConnection - parameter problem
- From: "William \(Bill\) Vaughn" <billvaRemoveThis@xxxxxxxxxx>
- Date: Sat, 17 Feb 2007 15:11:37 -0800
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
.
- Follow-Ups:
- Re: OdbcConnection - parameter problem
- From: David Thielen
- Re: OdbcConnection - parameter problem
- Prev by Date: Re: Simple way of finding whether a certain value is in a DataSet column
- Next by Date: problem using stored procedures in dotnet
- Previous by thread: sql server return parameter size.
- Next by thread: Re: OdbcConnection - parameter problem
- Index(es):
Relevant Pages
|