PDA

View Full Version : ADO Command vs RecordSet


pinkcat_02
04-16-2003, 04:39 PM
I am trying to implement an admin site but I am confused as I managed to display the data stored in my tables with ADO command but fail to do the same with recordset.

I was wondering if Ado command is the only way of retrieving the datas stored in the tables??? I have been using recorset till now for my queries of retrieving data but i couldn't manage to make it work with this task.

:confused:

Spudhead
04-16-2003, 05:37 PM
I think we're gonna need to see some code...

Usually, it's common to use a recordset object to execute a query that.. returns records (ie: a SELECT statement), and a command object to execute anything that doesn't (ie: an UPDATE). Or at least it's common the way I do it :)

pinkcat_02
04-16-2003, 05:53 PM
<%

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("x.mdb"))

Set admin = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT * FROM tblEmployees"
admin.Open SQL, oConn, 0, 2, adCmdText




I have tried this one to do the same thing with the code below. The code below does what I want but the one above doesn't.





<%

Dim DataConnection, cmdDC, RecordSet
Dim RecordToDelete

'-- Create object and open database

Set DataConnection = Server.CreateObject("ADODB.Connection")
DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("x.mdb")


Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection

SQL = "SELECT * FROM tblEmployees"

cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")

RecordSet.Open cmdDC, , 0, 2


and the data I want to display is this one :
Response.Write(" <td>" & RecordSet.Fields("ID") & "</td>" & Chr(13))

Thanks

Roy Sinclair
04-16-2003, 09:54 PM
Try the change indicated below, I rarely ever use a command object.


<%

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("x.mdb"))

Set admin = Server.CreateObject("ADODB.Recordset")
Set admin.ActiveConnection = oConn
SQL = "SELECT * FROM tblEmployees"
admin.Open SQL, oConn, 0, 2, adCmdText

miranda
04-17-2003, 01:55 AM
you can do it without the recordset object like so and it is faster too

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("x.mdb"))

SQL = "SELECT * FROM tblEmployees"
Set admin = oConn.Execute(SQL)

whammy
04-17-2003, 02:12 AM
Yeah, unless you need to use a recordset object (for instance "For each item in rs.Fields", or looping through the recordset), you don't need one.

miranda
04-17-2003, 02:29 AM
you can use a loop without using the recordset object

whammy
04-17-2003, 02:43 AM
Yeah use GetRows()