Forum Discussion
mesg2anil
14 years agoRegular Contributor
Hi Robert,
Thanks for the info...
As you suggested, I modified the code as below... I can see all the records displaying, but when I modified the SQL select query but it is not giving the results as per the SQL query... could you please help in this regard...!?!?
Sub TestSQL_ADO2
'Creates ADO connection
Set aCon = ADO.CreateConnection
'Sets up the connection parameters
aCon.ConnectionString = "Driver={SQL Server};" & _
"Server=WIN2K;" & _
"Database=INR;"
'Opens the connection
aCon.Open
'Creates a command and specifies its parameters
Set aCmd = ADO.CreateCommand
Set aCmd.ActiveConnection = aCon ' Connection
aCmd.CommandType = adCmdTable ' Command type
aCmd.CommandText = "controlinfo" ' Table name
' Opens a recordset
Set aRecSet = aCmd.Execute("select * from controlinfo where Module like 'rental' and submodule = 'leads'") 'I'm not getting the results as per this SQL query, it is displaying all the records
aRecSet.MoveFirst
' Obtains field names
s = ""
For i = 0 To aRecSet.Fields.Count - 1
s = s & aRecSet.Fields.Item(i).Name & vbTab
Next
s = s & vbCrLf
' Scans recordset
Do While Not aRecSet.EOF
For i = 0 To aRecSet.Fields.Count - 1
s = s & aRecSet.Fields.Item(i).Value & vbTab
Next
s = s & vbCrLf
aRecSet.MoveNext
Loop
' Outputs results
Log.Message "controlinfo", s
' Closes the recordset and connection
aRecSet.Close
aCon.Close
End Sub
Thanks for the info...
As you suggested, I modified the code as below... I can see all the records displaying, but when I modified the SQL select query but it is not giving the results as per the SQL query... could you please help in this regard...!?!?
Sub TestSQL_ADO2
'Creates ADO connection
Set aCon = ADO.CreateConnection
'Sets up the connection parameters
aCon.ConnectionString = "Driver={SQL Server};" & _
"Server=WIN2K;" & _
"Database=INR;"
'Opens the connection
aCon.Open
'Creates a command and specifies its parameters
Set aCmd = ADO.CreateCommand
Set aCmd.ActiveConnection = aCon ' Connection
aCmd.CommandType = adCmdTable ' Command type
aCmd.CommandText = "controlinfo" ' Table name
' Opens a recordset
Set aRecSet = aCmd.Execute("select * from controlinfo where Module like 'rental' and submodule = 'leads'") 'I'm not getting the results as per this SQL query, it is displaying all the records
aRecSet.MoveFirst
' Obtains field names
s = ""
For i = 0 To aRecSet.Fields.Count - 1
s = s & aRecSet.Fields.Item(i).Name & vbTab
Next
s = s & vbCrLf
' Scans recordset
Do While Not aRecSet.EOF
For i = 0 To aRecSet.Fields.Count - 1
s = s & aRecSet.Fields.Item(i).Value & vbTab
Next
s = s & vbCrLf
aRecSet.MoveNext
Loop
' Outputs results
Log.Message "controlinfo", s
' Closes the recordset and connection
aRecSet.Close
aCon.Close
End Sub