Forum Moderators: open
Thank you
Ok I was able to get the following example code to access the first record where "firstname=Joe" but if I input the second record where "firstname=Bob", the page fails to compile. How do I access any single record?
The Access table assigned to odbc_object looks like:
id ¦ firstname ¦ lastname
---------------------------
1 ¦ Joe ¦ Mills
2 ¦ Bob ¦ Johnston
<%
Dim rs
Set rs = Server.CreateObject ("ADODB.Recordset")
rs.Open "table1", "DSN=odbc_object"
If rs("firstname")="Joe" then
Response.Write "ID: " & rs("id") & "<br>"
Response.Write "First Name: " & rs("firstname") & "<br>"
Response.Write "Last Name: " & rs("lastname") & "<br>"
End If
rs.Close
Set rs = Nothing
%>
You should also look at some SQL tutorials. If you only need one record from your database you would use a select statement like: "SELECT * FROM Table WHERE Name='Bob'"
This would then return just that row for you to work with. If you want your code to work as you posted using ADODB and no SQL query, you'd need to at least put the IF statement in some kind of loop and go through all of the records until you found firstname='Bob'
rs.Open "SELECT * FROM 05schedule WHERE team1=49ers", "DSN=football"
Thank you! There is something else though. Rather than WHERE team1=49ers I want to pass a variable to the statement like WHERE team1=Request("TEAMNAME"). This doesn't work though and declaring a variable first such as teamname=Request(“TEAMNAME”) to set team1 equal to doesn't work either. Any suggestions?
I’ll look into ADO.Net, since I’m familiar with classic ASP I thought this an easier route for starters. Thank you for the welcome!
49ers' or 1=1 or team1='49ers
The query would return all the teams, not just the 49ers.
Now, in this case it may not be critical, but you should always be thinking about it. Parameterized queries avoids this problem.