I've tried unsuccessfully to find a really simple example. I'm close but something is still wrong. I want to use bind variables in a VB program I'm writing. I keep getting missing oracle expression if I use @ for my bind variables. If I use & for them, I get not all variables are bound
Dim cnt As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As ADODB.Command
Dim par As ADODB.Parameter
Dim test As String
Dim plcynbr As String
Dim sSQL As String
Dim lngLenName As String
lngsize = 50
lngLenName = "'bozo test'"
sSQL = "UPDATE MyTable SET ID_Name = @theName WHERE ID = @id"
dbConnectStr = "Provider=msdaora;Data Source=P1ltcent;User ID=userid;Password=password"
cnt.ConnectionString = dbConnectStr
cnt.Open dbConnectStr
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = cnt
.CommandType = adCmdText
.CommandText = sSQL
Set par = .CreateParameter("@theName", adVarChar, adParamInput, lngsize, lngLenName)
.Parameters.Append par
Set par = .CreateParameter("@id", adInteger, adParamInput, , 1)
.Parameters.Append par
For Each prm In .Parameters
Debug.Print prm.Name & " : " & prm.Value
Next
Debug.Print cmd.CommandText
.Execute , , adCmdText And adExecuteNoRecords
End With
So I displayed my parameters and they look good to me &theName : 'bozo test' &id : 1
I displayed my SQL and it looks good to me
UPDATE MyTable SET ID_Name = &theName WHERE ID = &id
but I'm still getting not all variables bound
?or:theNameinstead of@theName. Parameter must be without i.e.Set par = .CreateParameter("theName", adVarChar, adParamInput, lngsize, lngLenName)lngLenName = "bozo test"instead oflngLenName = "'bozo test'"- that is the purpose of bind variables, you don't have to quote or escape the values.