Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
avoid an error [SQL/read a table with nothing in it]
Old 02-29-2008, 12:28 AM avoid an error [SQL/read a table with nothing in it]
Extreme Talker

Posts: 176
Trades: 0
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
 
 
Register now for full access!
Old 02-29-2008, 02:43 AM Re: avoid an error [SQL/read a table with nothing in it]
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Absolutely possible. Not the best way to go about things, but possible.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-29-2008, 03:19 AM Re: avoid an error [SQL/read a table with nothing in it]
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-29-2008, 05:29 AM Re: avoid an error [SQL/read a table with nothing in it]
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.13446 seconds with 12 queries