[thelist] ASP, SQL, Recordsets, Best Practices

Scott Dexter sgd at ti3.com
Thu Mar 1 14:36:48 CST 2001


> When querying a unique field in a database, and the answer is 
> either "yes a
> record exists" or "no record exists", is it necessary to 
> still loop through

Rudy, you take this one =)

> 
> Or, is declaring the fields an unnecessary step, IF the field 
> is only being
> written/used once?
> 
> i.e.    response.write rs("sizefromdb")

*ONLY* once?

yeah, that would be better, but you're holding the recordset open too long.
Inside your loop (I presume the loop in (1) above) when you get the value,
assign it to a variable, then close the recordset. Basically, you want to
get the value and get out of the db as fast as you can, so:

<%

Set oRS=oDBCON.Execute ("Select blah blah rudy is tha man")
if oRS.BOF and oRS.EOF then
	sizefromdb=Empty
else
	sizefromtb=oRS(0) ' the first column, this is faster than by name
	oRS.Close
end if
Set oRS = Nothing
Set oDBCON = Nothing

...

%>

make sense?

sgd




More information about the thelist mailing list