Rexolio
Technical User
- Aug 29, 2001
- 230
Hi... just had a simple question that I was curious about. I try to be very complete with my coding, using "Dim" and closing recordsets and command objects.
In the past when I want to return a specific record according to an ID number where there is going to be only 1 record, I have still been using the following code:
----------------------------
set rsList=Conn.execute("select * from table where id = " & id & ""
do while not rsList.eof
name = rsList("name"
rsList.movenext
loop
rsList.close
-----------------------------
I thought this was the proper way to do it, even though there's extra code thats not necessarily needed.
I recently started doing the following for this type of situation (one record):
-----------------------------
set rsList = same as above
if rsList.eof then
Response.write ("No such record"
else
name = rsList("name"
end if
rsList.close
--------------------------------
Maybe a silly question and I'm still pretty new to this stuff, but is this okay? It works fine, of course. But I'd rather avoid and incorrect scripting or bad practices that may cause problems in the future.
Thanks for your time.
In the past when I want to return a specific record according to an ID number where there is going to be only 1 record, I have still been using the following code:
----------------------------
set rsList=Conn.execute("select * from table where id = " & id & ""
do while not rsList.eof
name = rsList("name"
rsList.movenext
loop
rsList.close
-----------------------------
I thought this was the proper way to do it, even though there's extra code thats not necessarily needed.
I recently started doing the following for this type of situation (one record):
-----------------------------
set rsList = same as above
if rsList.eof then
Response.write ("No such record"
else
name = rsList("name"
end if
rsList.close
--------------------------------
Maybe a silly question and I'm still pretty new to this stuff, but is this okay? It works fine, of course. But I'd rather avoid and incorrect scripting or bad practices that may cause problems in the future.
Thanks for your time.