no, the confusion was because i had SQL Express at first but then was forced to go with Access. so i didnt know what would still work. it has been pointed out that this code is bad:
<%
Dim oConn, oRS, randNum
Set oConn=Server.CreateObject("ADODB.Connection")
Set oRS=Server.CreateObject("ADODB.recordset")
oConn.Provider="Microsoft.Jet.OLEDB.4.0"
oConn.Open Server.MapPath("temp.mdb")
oRS.Open "SELECT EMAIL_ADDRESS FROM TABLE1", oConn, adOpenStatic, adLockReadOnly
Randomize()
randNum = CInt((oRS.RecordCount - 1) * Rnd)
Response.Write("RecordCount: " & oRS.RecordCount & "<br><br>")
oRS.Move randNum
Response.Write oRS("EMAIL_ADDRESS")
oRS.close
oConn.close
Set oConn = nothing
Set oRS = nothing
%>
so i wanted to know if the "TOP 1" method could be done in access, and maybe see an example based on what i have here.
Aaron Bertrand said:
What, this?
Again, you need to show us what you are doing with randNum before we can
comment.
But yes, as we've already suggested, there are issues.
My guess is you are going to say
sql = "SELECT EmailAddress FROM Table1 WHERE PK = " & RandNum
And like I already commented, this won't work reliably. Never mind the
unnecessary roundtrip to count the number of rows in the table.
I think you need to stop theorizing code and deal with this when you can
actually test it against a real database and understand the differences and
what we are talking about. Until then it seems you are hellbent on just
doing it your way and ignoring our advice.
A
------=_NextPart_000_0049_01C6D359.C5231A80
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Google-AttachSize: 4297
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2>no, the confusion
was because i had SQL Express at first but then was forced to go with Access. so
i didnt know what would still work. it has been pointed out that this code is
bad:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial color=#0000ff
size=1><STRONG><%<BR>Dim oConn, oRS, randNum</STRONG></FONT></DIV><FONT
face=Arial color=#0000ff size=1><STRONG>
<DIV><BR>Set oConn=Server.CreateObject("ADODB.Connection")<BR>Set
oRS=Server.CreateObject("ADODB.recordset")</DIV>
<DIV><BR>oConn.Provider="Microsoft.Jet.OLEDB.4.0"<BR>oConn.Open
Server.MapPath("temp.mdb")</STRONG></FONT></DIV>
<DIV><STRONG><FONT color=#0000ff size=1></FONT></STRONG> </DIV>
<DIV><FONT face=Arial color=#0000ff size=1><STRONG>oRS.Open "SELECT
EMAIL_ADDRESS FROM TABLE1", oConn, adOpenStatic,
adLockReadOnly<BR>Randomize()<BR>randNum = CInt((oRS.RecordCount - 1) *
Rnd)</STRONG></FONT></DIV>
<DIV><FONT face=Arial color=#0000ff
size=1><STRONG><BR>Response.Write("RecordCount: " & oRS.RecordCount &
"<br><br>")</STRONG></FONT></DIV>
<DIV><STRONG><FONT color=#0000ff size=1></FONT></STRONG> </DIV>
<DIV><FONT face=Arial color=#0000ff size=1><STRONG>oRS.Move
randNum<BR>Response.Write oRS("EMAIL_ADDRESS")</STRONG></FONT></DIV>
<DIV><STRONG><FONT color=#0000ff size=1></FONT></STRONG> </DIV>
<DIV><FONT face=Arial color=#0000ff
size=1><STRONG>oRS.close<BR>oConn.close<BR>Set oConn = nothing<BR>Set oRS =
nothing<BR>%></STRONG></FONT></DIV>
<DIV><STRONG><FONT color=#0000ff size=1></FONT></STRONG> </DIV>
<DIV>so i wanted to know if the "TOP 1" method could be done in access, and
maybe see an example based on what i have here.</DIV></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>"Aaron Bertrand [SQL Server MVP]" <</FONT><A
href="mailto:
[email protected]"><FONT face=Arial
size=2>
[email protected]</FONT></A><FONT face=Arial size=2>> wrote in
message </FONT><A href="face=Arial size=2>face=Arial size=2>...</FONT></DIV><FONT face=Arial size=2>> What,
this?<BR>> <BR>>>> randNum = (CInt((recordcount-1) * Rnd) +
1)<BR>> <BR>> Again, you need to show us what you are doing with randNum
before we can <BR>> comment.<BR>> <BR>> But yes, as we've already
suggested, there are issues.<BR>> <BR>> My guess is you are going to
say<BR>> <BR>> sql = "SELECT EmailAddress FROM Table1 WHERE PK = " &
RandNum<BR>> <BR>> And like I already commented, this won't work
reliably. Never mind the <BR>> unnecessary roundtrip to count the
number of rows in the table.<BR>> <BR>> I think you need to stop
theorizing code and deal with this when you can <BR>> actually test it
against a real database and understand the differences and <BR>> what we are
talking about. Until then it seems you are hellbent on just <BR>> doing
it your way and ignoring our advice.<BR>> <BR>> A<BR>> <BR>>
<BR>> <BR>> <BR>> "Jimmy" <</FONT><A href="mailto:
[email protected]"><FONT
face=Arial size=2>
[email protected]</FONT></A><FONT face=Arial size=2>> wrote in message
<BR>> </FONT><A href="face=Arial size=2>face=Arial size=2>...<BR>>> thank you.<BR>>> im currently testing
with an access db. do you see any issues with my <BR>>> previous random
record generating code?<BR>> <BR>></FONT></BODY></HTML>
------=_NextPart_000_0049_01C6D359.C5231A80--