Reply
avoid an error [SQL/read a table with nothing in it]
Old 02-28-2008, 11:28 PM avoid an error [SQL/read a table with nothing in it]
Skilled Talker

Posts: 77
Code:
Rs.Open "SELECT * FROM tblUsers WHERE tblUsers.username = '" & uname & "';", Conn, 1,3
This is what I have as my log in script, and it works if the name exists, but if it doesn't, it tries to deal with it by giving it an error. I want to deal with it myself, like this:

Code:
if not rs.EOF then
'things that are set if there are no entries
end if
Possible?
Skeddles is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 02-29-2008, 01:43 AM Re: avoid an error [SQL/read a table with nothing in it]
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Absolutely possible. Not the best way to go about things, but possible.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-29-2008, 02:19 AM Re: avoid an error [SQL/read a table with nothing in it]
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,025
Name: Forrest Croce
Location: Seattle, WA
If the table doesn't exist and you try to query it, the database will throw an error to tell your asp script something went wrong, and it can't just go on. You don't get an empty result set.

Code:
On Error Resume Next

rs.Open "Select * From a_table_that_doesnt_exist"

If rs.EOF or rs.BOF ...
If you wanted to get really sophisticated but abstract, you could make a routine to query the mSysObjects table - I'm assuming you're using Microsoft Access. There's a type and a name column, so you can write code that knows whether a table exists before trying to query it.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-29-2008, 04:29 AM Re: avoid an error [SQL/read a table with nothing in it]
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Code:
if not rs.EOF then
'things that are set if there are no entries
end if
Would handle the End Of File error but you should handle the Beginning Of File error as well

or check the error object from the ADO Errors collection

Code:
On Error Resume Next

objRS.open ....  


if objRS.Errors.number <> 0 then
    do error handling
end if
http://www.devguru.com/technologies/ADO/8591.asp
http://www.devguru.com/technologies/ADO/8757.asp

A list of ADO error codes can be found at http://www.devguru.com/technologies/ADO/8596.asp


for no records existing the error is adErrNoCurrentRecord

IF you use the error object make sure that you clear it before calling a method that may raise an exception.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to avoid an error [SQL/read a table with nothing in it]
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12586 seconds with 13 queries