Click to See Complete Forum and Search --> : Code Error?


ianripping
02-25-2004, 12:59 PM
Can anyone tell me what is incorrec about his code?

My access file is called FeedBack.mdb, my table is called tblFeeds and my fields are called "name" and "comments"

<%
Dim Conn
Dim Rs
Dim sql
'Create an ADO connection and recordset object
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
'Set an active connection and select fields from the database
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("FeedBack.mdb")
sql= "SELECT name, comments FROM tblFeeds;"

'Set the lock and cursor type
Rs.CursorType = 2
Rs.LockType = 3

Rs.Open sql, Conn 'Open the recordset with sql query

set rs = server.createObject("ADODB.recordSet") '|Set the ADO recordSet object.

sql_query = "SELECT TOP 1 * FROM tblFeeds ORDER BY rec_id DESC"
rs.open(sql_query) '|Execute the SQL query.

'|Now we print the record out to the screen.
response.write("Name: " & rs("name") & vbCrLf)
response.write("Comments: " & rs("comments") & vbCrLf)

Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>

athankon
02-25-2004, 06:31 PM
what kind of error do you get ?

better Post it here

buntine
02-26-2004, 01:00 AM
A few things:

- ASP is not case-sensitive. Ultimately Rs and rs are the same thing. Try using rs and rso for your recordSet objects.

- Also, have you set the 'rec_id' field in your database as autonumber?

- Finally, you have queryed the database twice. Why did you select the records from the DB and then select the same records again?

Regards,
Andrew Buntine.