Caeser,
In your code you're getting the entire 'dataentry' table into the recordset whereas dhtmlgod simply used an sql query to get just the 'Answer' and 'Chosen' fields from the table, which is more efficient. Having got the entire table into the recordset you then try to execute an sql string which causes the problem because the recordset object doesn't have an Execute method and even if it did it'd be unnecessary as you've already got the data in the recordset.
Because you've opened the entire table you could actually just remove the following line and I think it'd work.
Code:
Set compareAnswer = rs.Execute("SELECT Answer, Chosen FROM dataentry")
dhtlgod, used the Execute method of the connection object which can (and in this instance does) return a recordset object.
Code:
'--So instead of:
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "dataentry", "DSN=MyStats"
Set compareAnswer = rs.Execute("SELECT Answer, Chosen FROM dataentry")
'--You can use either open the recordset using the connection execute method or using the recordset open method.
'Set up sql
strSQL = "SELECT Answer, Chosen FROM dataentry"
'Create connection object
Set objConn = Server.CreateObject("ADODB.Connection")
'Open connection
objConn.Open "DSN=MyStats"
'Method 1
'Open recordset using connection execute method
Set objRS = objConn.Execute(strSQL)
'Method 2
'Set the required recordset properties
With objRS
.ActiveConnection = objConn
.Source = strSQL
.Open
End With
The second method does give more flexibilty, if needed, as you can specify different recordset properties which you can't if you use the execute method.
With ADO there's often a bunch of different ways that something can be done which can lead to some confusion.
I hope this helps.
Bookmarks