Query MS-SQL database through TC
Using below code, I'm trying to query a table in MS-SQL server, it is giving me table fieldnames but it is not displaying the data from each field.
Sub TestSQL
'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") 'I've a doubt here, is this the correct syntax to fetch the data from table?
aRecSet.MoveFirst
'Obtains field names
s = ""
For i = 0 To aRecSet.Fields.Count - 1
s = s & aRecSet.Fields.Item(i).Name & vbTab
Next
'Outputs results
Log.Message s
Log.Message aRecSet
'Closes the recordset and connection
aRecSet.Close
aCon.Close
End Sub