• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

ASP SQL Programming

sswingle

Diamond Member
Ok, so I am teaching myself how to access databases using ASP. I can add records, update records, and display lots of records, but I cant seem to figure out how to access a single specific record. I am probably just missing something very simple.

I have a variable called form_id. I also have in my table a unique number called id. All I want to do is open the record where id=form_id
So I have:
sql= "Select * FROM users WHERE id="&form_id

But then my page just shows the first record, which is id 1

I had attempted an rs.Move form_id
but that command opens up the wrong record, as it is going by database record instead of the id field, from what I can tell.

Is there any way to match the database record to the one that has the correct id? ID is a primary key, so it is impossible for that to match to more than one record.

Thanks!
 
I'm not sure I really understand the problem.

Let's say form_id = 5,

Then the statement, "Select * FROM users WHERE id = 5" would return the row from the users table which has 5 in its "id" column.

Is the problem that your form_id's don't actually match the numbers in the ID column of the users table?
 
Originally posted by: Kilrsat
I'm not sure I really understand the problem.

Let's say form_id = 5,

Then the statement, "Select * FROM users WHERE id = 5" would return the row from the users table which has 5 in its "id" column.

Is the problem that your form_id's don't actually match the numbers in the ID column of the users table?

The problem is that I run the select statement, but when I display records, for example <%=rs("id")%> will display 1, which is the first record, even though I just selected 5
 
Originally posted by: ScottSwingleComputers
Originally posted by: Kilrsat
I'm not sure I really understand the problem.

Let's say form_id = 5,

Then the statement, "Select * FROM users WHERE id = 5" would return the row from the users table which has 5 in its "id" column.

Is the problem that your form_id's don't actually match the numbers in the ID column of the users table?

The problem is that I run the select statement, but when I display records, for example <%=rs("id")%> will display 1, which is the first record, even though I just selected 5

Need the rest of the code. This is probably a bug somewhere in your code.

You could do RS.Find() but that would just be correcting for whatever is causing the underlying problem.
 
If Not rs.BOF Then
rs.MoveFirst
End If

While Not rs.EOF
For Each x In rs.Fields
Response.Write x.Name & " = " & x.Value & "<BR>"
Next
rs.MoveNext
Wend


a greate site for this kind of stuff is DevGuru
 
Back
Top