PC Review


Reply
Thread Tools Rate Thread

BIND VARIABLES using 'Like' in the sql

 
 
RDS
Guest
Posts: n/a
 
      18th Aug 2005
How can I do the following using LIKE%% with wildcards instead of =
?

code:

oCon = New Oracle.DataAccess.Client.OracleConnection
sSql = "SELECT * FROM TABLE Where NAME = Name "

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

pInParam.Value = "Company"

With cmdMyCommand
.Connection = oCon
.CommandText = sSql
.Parameters.Add(pInParam)
.ExecuteNonQuery()
End With
'''

in other words, instead of 'Where NAME = Name'
I want to do 'Where NAME LIKE :%pName%'
I'm not sure of the correct syntax...

*****

Also, what is the difference in building up statements in this manner
using parameters, and using BIND VARIABLES, or is it the same thing?
One of our DBAs has asked me to look at re-writing my code to use bind
variables for the oracle db access as it is supposedly more efficient.
In VB6, '?' were used to denote where bind variables would be appended,
this no longer appears to be a valid character in .net..
Thanks in advance for any replies to the above

 
Reply With Quote
 
 
 
 
Paul Clement
Guest
Posts: n/a
 
      18th Aug 2005
On 18 Aug 2005 07:32:23 -0700, "RDS" <(E-Mail Removed)> wrote:

¤ How can I do the following using LIKE%% with wildcards instead of =
¤ ?
¤
¤ code:
¤
¤ oCon = New Oracle.DataAccess.Client.OracleConnection
¤ sSql = "SELECT * FROM TABLE Where NAME = Name "
¤
¤ Dim cmdMyCommand As New Oracle.DataAccess.Client.OracleCommand
¤ Dim pInParam As New Oracle.DataAccess.Client.OracleParameter
¤
¤ pInParam.Value = "Company"
¤
¤ With cmdMyCommand
¤ .Connection = oCon
¤ .CommandText = sSql
¤ .Parameters.Add(pInParam)
¤ .ExecuteNonQuery()
¤ End With
¤ '''
¤
¤ in other words, instead of 'Where NAME = Name'
¤ I want to do 'Where NAME LIKE :%pName%'
¤ I'm not sure of the correct syntax...
¤
¤ *****
¤
¤ Also, what is the difference in building up statements in this manner
¤ using parameters, and using BIND VARIABLES, or is it the same thing?
¤ One of our DBAs has asked me to look at re-writing my code to use bind
¤ variables for the oracle db access as it is supposedly more efficient.
¤ In VB6, '?' were used to denote where bind variables would be appended,
¤ this no longer appears to be a valid character in .net..
¤ Thanks in advance for any replies to the above

AFAIK the '?' character is still supported in ADO.NET, at least for OLEDB.

Using a named parameter should be supported as well for the .NET Oracle provider. When you add your
parameter, just make sure to specify the name as "pName" (according to your above example).


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bind variables and sql cptkirkh Microsoft ADO .NET 4 8th Aug 2007 02:55 PM
How to bind variables everymn@yahoo.com Microsoft Access VBA Modules 5 21st Nov 2006 11:54 PM
Bind Variables Using ODP.NET vm.shinde@gmail.com Microsoft ADO .NET 0 24th Feb 2006 12:37 PM
Bind variables in vb.net RDS Microsoft VB .NET 3 18th Aug 2005 06:43 PM
Is there a way to bind form variables? dave Microsoft VB .NET 0 18th Nov 2003 08:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:50 AM.