Using Oracle bind variables from VB via ADO 
Author Message
 Using Oracle bind variables from VB via ADO

Hi
Does anyone know how to use Oracle bind variables from VB via ADO?
I have a query:

select MyField from MyTable where KeyField = <literal>

...which gets run quite frequently, with different values for the literal.
I know it's more efficient to use a bind variable in place of the literal -
but how?  What is the correct syntax?

Please email me directly as well as replying to the group (Remove
.antispam).

Many thanks,
Saul



Sat, 15 May 2004 21:10:13 GMT  
 Using Oracle bind variables from VB via ADO
The command object in VB is what you use for Oracle bind variables:
Example:
**************************************************
dim conn            As ADODB.Connection
dim cmd             As ADODB.Command
dim mySQLString     As String

'[be sure to initialize the conn and cmd objects somewhere]

mySQLString = "DELETE FROM MyTable WHERE Company = ? AND Dept = ?"

 With cmd
     If .ActiveConnection Is Nothing Then
         Set .ActiveConnection = conn
     End If
     .CommandText = mySQLString
     .Prepared = True  'use this for long SQL statements only
     .Parameters.Append .CreateParameter(, adVarChar, , 35, MyCompVariable)
     .Parameters.Append .CreateParameter(, adVarChar, , 20, MyDeptVariable)
     .Execute , , adCmdText + adExecuteNoRecords
End With
******************************************
This code is for deleting, updating, and inserting.
The code for selecting is below:
******************************************
dim tbl As ADODB.Recordset

mySQLString = "SELECT * FROM MyTable WHERE Dept = ?"

 With cmd
     If .ActiveConnection Is Nothing Then
         Set .ActiveConnection = conn
     End If
     .CommandText = mySQLString
     .Prepared = True 'use this for long SQL statements only
    .Parameters.Append .CreateParameter(, adVarChar, , 20, MyDeptVariable)
     Set tbl  = .Execute(, , adCmdText)
End With



Mon, 17 May 2004 11:22:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Using Oracle bind variables on an INSERT

2. Binding variables with VB 6.0 ADO

3. CAlling an Oracle Stored Proc with ADO.Net via VB

4. Changing password in Oracle using PASSWORD command via VB app

5. Changing password in Oracle using PASSWORD command via VB app

6. Saving Rich Text Format (RTF) in Oracle 10g using PL/SQL via VB/ASP.NET

7. Help:How to avoid Oracle Logon window for VB to Oracle via attached Access

8. Embedded SQL and Oracle bind variables

9. help with oracle performance : using ado, oracle longraw fields

10. Trouble with ADO in VB5 to Oracle 7.33, using the Oracle 73 driver

11. help with oracle performance : using ado, oracle 8 longraw field

12. help with oracle performance : using ado, vb6, oracle 8 longraw field

 

 
Powered by phpBB® Forum Software