Hi to all,

having some trouble to get the following to work:


Set con = CreateObject("ADODB.Connection")
con.Open "DSN=DATACOMP",user
SQL = "SELECT * FROM dc_time"
Set rs = CreateObject("ADODB.Recordset")

rs.Open SQL, con
rs.movefirst

I'd like to end the script if the SQL command returns no entries in dc_time
I tried but couldn't get it to work...


For soon replay thanks in advance!

Regards,
Markus

Re: If Recordset empty - wscript.quit! by gandrewsjr_

gandrewsjr_
Wed Aug 18 09:19:59 CDT 2004

How about this ...

Set con = CreateObject("ADODB.Connection")
con.Open "DSN=DATACOMP",user
SQL = "SELECT * FROM dc_time"
Set rs = CreateObject("ADODB.Recordset")

rs.Open SQL, con
if not rs.EOF then
rs.movefirst
while not.rs.EOF
'do something with rs
rs.movenext
wend

' continue with whatever ...

end if

con.close
Set rs=nothing
Set con=nothing
wscript.quit


In article <OKoTboShEHA.3236@TK2MSFTNGP10.phx.gbl>,
noreply_possible@spam-hater.com says...
>
>Hi to all,
>
>having some trouble to get the following to work:
>
>
>Set con = CreateObject("ADODB.Connection")
>con.Open "DSN=DATACOMP",user
>SQL = "SELECT * FROM dc_time"
>Set rs = CreateObject("ADODB.Recordset")
>
>rs.Open SQL, con
>rs.movefirst
>
>I'd like to end the script if the SQL command returns no entries in dc_time
>I tried but couldn't get it to work...
>
>
>For soon replay thanks in advance!
>
>Regards,
>Markus
>
>


Re: If Recordset empty - wscript.quit! by Bob

Bob
Wed Aug 18 09:35:04 CDT 2004

Andy G wrote:
> How about this ...
>
> Set con = CreateObject("ADODB.Connection")
> con.Open "DSN=DATACOMP",user
> SQL = "SELECT * FROM dc_time"
> Set rs = CreateObject("ADODB.Recordset")
>
> rs.Open SQL, con
> if not rs.EOF then
> rs.movefirst

The movefirst is not necessary, and in some cases (forwardonly cursors), may
cause your recordset to be requeried (another trip to the database - bad).
The cursor is already pointing to the first record immediately after opening
the recordset, as is the case here.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: If Recordset empty - wscript.quit! by Markus

Markus
Wed Aug 18 10:26:30 CDT 2004

Hi,

found a solution in the meantime:

VBscript help says:
If you open a Recordset object containing no records, the BOF and EOF
properties are set to True

So I do:

if rs.BOF= -1 AND rs.EOF = -1 then
...

Regrds,
Markus

"Markus Mannheim" <noreply_possible@spam-hater.com> schrieb im Newsbeitrag
news:OKoTboShEHA.3236@TK2MSFTNGP10.phx.gbl...
> Hi to all,
>
> having some trouble to get the following to work:
>
>
> Set con = CreateObject("ADODB.Connection")
> con.Open "DSN=DATACOMP",user
> SQL = "SELECT * FROM dc_time"
> Set rs = CreateObject("ADODB.Recordset")
>
> rs.Open SQL, con
> rs.movefirst
>
> I'd like to end the script if the SQL command returns no entries in
dc_time
> I tried but couldn't get it to work...
>
>
> For soon replay thanks in advance!
>
> Regards,
> Markus
>
>



Re: If Recordset empty - wscript.quit! by Bob

Bob
Wed Aug 18 10:39:59 CDT 2004

Markus Mannheim wrote:
> Hi,
>
> found a solution in the meantime:
>
> VBscript help says:
> If you open a Recordset object containing no records, the BOF and EOF
> properties are set to True
>
> So I do:
>
> if rs.BOF= -1 AND rs.EOF = -1 then
> ...

It's not a big deal, but, you don't have to check both immediately after
opening the recordset. EOF is the only property that needs to be checked.

If you navigate through the recordset (Move, MoveNext, etc.) or delete
records from it, then it becomes necessary to check both BOF and EOF so see
if it contains records.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.