recordcount never equals 0 !
recordcount never equals 0 !
am 10.01.2005 14:04:58 von Ben
Hi,
i need to do something when the recordcount is 0, but it the result is
always ">0", what means that "recname" never equals 0. Why? And how to
handle the case there is no records?
<%
set OBJDC = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source =c:\mytable.mdb")
sql="SELECT name from tname WHERE name='John' ;"
dim rsArray
Set rs = objdc.execute(sql)
if rs.eof then
recname=0
else
rsArray = rs.GetRows()
recname = UBound(rsArray, 2) + 1
end if
if recname=0 then
response.write("=0") 'doesn't work
else
response.write(">0")
end if
%>
Thanks
ben
Re: recordcount never equals 0 !
am 10.01.2005 14:19:20 von reb01501
Ben wrote:
> Hi,
>
> i need to do something when the recordcount is 0, but it the result is
> always ">0", what means that "recname" never equals 0.
> Why?
Umm, because your query is returning records?
> And how to
> handle the case there is no records?
You already are. I would make a slight modification to your code to make it
more efficient. See below.
>
> <%
> set OBJDC = Server.CreateObject("ADODB.Connection")
> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
> =c:\mytable.mdb") sql="SELECT name from tname WHERE name='John' ;"
>
> dim rsArray
> Set rs = objdc.execute(sql)
> if rs.eof then
> recname=0
> else
> rsArray = rs.GetRows()
> recname = UBound(rsArray, 2) + 1
> end if
>
> if recname=0 then
> response.write("=0") 'doesn't work
> else
> response.write(">0")
> end if
> %>
>
> Thanks
> ben
if not rs.eof then rsArray = rs.GetRows()
'***********************************
'close and destroy your ado objects as soon as
'you no longer need them:
'***********************************
rs.close: Set rs=nothing
objdc.close: set objdc = nothing
recname=0 'why recname? why not recCount?
if isArray(rsArray) then
recname = UBound(rsArray, 2) + 1
end if
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: recordcount never equals 0 !
am 10.01.2005 14:31:30 von fhickman_NOSP
Not only that but your also adding 1 to recname so it would never be 0.
>> recname = UBound(rsArray, 2) + 1
--
============
Frank Hickman
Microsoft MVP
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
"Bob Barrows [MVP]" wrote in message
news:eOuUAcx9EHA.608@TK2MSFTNGP15.phx.gbl...
> Ben wrote:
>> Hi,
>>
>> i need to do something when the recordcount is 0, but it the result is
>> always ">0", what means that "recname" never equals 0.
>> Why?
>
> Umm, because your query is returning records?
>
>> And how to
>> handle the case there is no records?
>
> You already are. I would make a slight modification to your code to make
> it
> more efficient. See below.
>
>>
>> <%
>> set OBJDC = Server.CreateObject("ADODB.Connection")
>> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
>> =c:\mytable.mdb") sql="SELECT name from tname WHERE name='John' ;"
>>
>> dim rsArray
>> Set rs = objdc.execute(sql)
>> if rs.eof then
>> recname=0
>> else
>> rsArray = rs.GetRows()
>> recname = UBound(rsArray, 2) + 1
>> end if
>>
>> if recname=0 then
>> response.write("=0") 'doesn't work
>> else
>> response.write(">0")
>> end if
>> %>
>>
>> Thanks
>> ben
>
> if not rs.eof then rsArray = rs.GetRows()
> '***********************************
> 'close and destroy your ado objects as soon as
> 'you no longer need them:
> '***********************************
> rs.close: Set rs=nothing
> objdc.close: set objdc = nothing
>
> recname=0 'why recname? why not recCount?
> if isArray(rsArray) then
> recname = UBound(rsArray, 2) + 1
> end if
>
> 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: recordcount never equals 0 !
am 10.01.2005 14:47:04 von reb01501
Umm, yes it will. That line of code will not execute if the recordset's eof
property is true.
Bob Barrows
Frank Hickman [MVP] wrote:
> Not only that but your also adding 1 to recname so it would never be
> 0.
>
>>> recname = UBound(rsArray, 2) + 1
>
>
> --
> ============
> Frank Hickman
> Microsoft MVP
> NobleSoft, Inc.
> ============
> Replace the _nosp@m_ with @ to reply.
>
>
> "Bob Barrows [MVP]" wrote in message
> news:eOuUAcx9EHA.608@TK2MSFTNGP15.phx.gbl...
>> Ben wrote:
>>> Hi,
>>>
>>> i need to do something when the recordcount is 0, but it the result
>>> is always ">0", what means that "recname" never equals 0.
>>> Why?
>>
>> Umm, because your query is returning records?
>>
>>> And how to
>>> handle the case there is no records?
>>
>> You already are. I would make a slight modification to your code to
>> make it
>> more efficient. See below.
>>
>>>
>>> <%
>>> set OBJDC = Server.CreateObject("ADODB.Connection")
>>> objdc.Open("provider=Microsoft.Jet.OLEDB.4.0; Data Source
>>> =c:\mytable.mdb") sql="SELECT name from tname WHERE name='John' ;"
>>>
>>> dim rsArray
>>> Set rs = objdc.execute(sql)
>>> if rs.eof then
>>> recname=0
>>> else
>>> rsArray = rs.GetRows()
>>> recname = UBound(rsArray, 2) + 1
>>> end if
>>>
>>> if recname=0 then
>>> response.write("=0") 'doesn't work
>>> else
>>> response.write(">0")
>>> end if
>>> %>
>>>
>>> Thanks
>>> ben
>>
>> if not rs.eof then rsArray = rs.GetRows()
>> '***********************************
>> 'close and destroy your ado objects as soon as
>> 'you no longer need them:
>> '***********************************
>> rs.close: Set rs=nothing
>> objdc.close: set objdc = nothing
>>
>> recname=0 'why recname? why not recCount?
>> if isArray(rsArray) then
>> recname = UBound(rsArray, 2) + 1
>> end if
>>
>> 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.
--
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.