Bind variables in vb.net

  • Thread starter Thread starter RDS
  • Start date Start date
R

RDS

Does anyone know how to do the following vb6 code using bind variables
for oracle dbs, in .net?

dim cmdMyCommand as ADODB.COMMAND
Set cmdMyCommand = New ADODB.COMMAND
With cmdMyCommand
.ActiveConnection = objConn
.CommandText = "Select COL1 from TABLENAME Where COL2 = ?"
.Parameters.Append .CreateParameter( "", _
adVarChar, adParamInputOutput, "SOMESTUFF")
Set rsMyRecordset = .Execute
End With

In the .net version I was trying to write it seems to complain about
the ?, in my code there are LIKE statements in the SQL as well, how can
bind variables be used [LIKE %?% doesn't work]

I was doing somthing like this:

Dim cmdMyCommand As Oracle.DataAccess.Client.OracleCommand
Dim pInParam As Oracle.DataAccess.Client.OracleParameter

cmdMyCommand = New Oracle.DataAccess.Client.OracleCommand
With cmdMyCommand
.Connection = oCon
.CommandText = "Select COL1 from TABLENAME Where COL2 = ?"
'OR .commandText = "Select COL1 from TABLENAME where value LIKE% ?
%"
.Prepare()
pInParam = New Oracle.DataAccess.Client.OracleParameter
pInParam.Value = sString.ToString()
.Parameters.Add(pInParam)
.ExecuteNonQuery()
End With
 
RDS,

Binding in Net is not the same as setting an sql parameter, which you cannot
bind.

I assume that your question is the last. We have two samples on our website
about SQL sever and OleDb for that.

http://www.windowsformsdatagridhelp.com/default.aspx?ID=886bba68-8a2f-4b99-8f66-7139b8970071

http://www.windowsformsdatagridhelp.com/default.aspx?ID=550279ec-6767-44ff-aaa3-eb8b44af0137


We don't have it for Oracle however see for the more general description
this

http://msdn.microsoft.com/library/d...leclientoraclecommandclassparameterstopic.asp

Did you know that for this kind of ADODB question the more properiate
newsgroups is

Adonet
news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet

Web interface:
http://communities2.microsoft.com/c.../?dg=microsoft.public.dotnet.framework.adonet

I hope this helps,

Cor
 
¤ RDS,
¤
¤ Binding in Net is not the same as setting an sql parameter, which you cannot
¤ bind.
¤

Cor,

The use of "Bind variables" is a different concept than "data binding". See the following:

http://www.rittman.net/archives/000832.html

Specifically he's just asking about the use of the Command object and named parameters. So if you
have a PL/SQL statement like the following:

select salary from employees where employee_number = :empno

You would add a Parameter object with the name "empno" to the Parameter collection in order to
support bind variables.


Paul
~~~~
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top