Simon Wigzell wrote:
> You'd think this would be the most basic sql query in the world but
> noooooo! I've tried this:
>
> on error resume next
> strsql = "SELECT * FROM " & session("TablePrefix") & CurrentTable
> SET rs = conn.execute(strsql)
>
> tableExists = 0
>
> if (Err.number = 0) then
> tableExists = 1
> end if
>
> But it doesn't return an error if the table doesn't exist.
Yes it does. Your problem is that you've executed a statement that does not
raise an error between the statement that raises an error (the Execute
statement) and the statement that tests the Err object for the existence of
an error. When a statement executes with no error, the Err object is
cleared. Move the "tableExists = 0" line to before the Execute statement.
That will allow you to see the error.
Better yet, check the connection object's Errors collection, which will not
be affected by the execution of subsequent vbscript statements.
> I'm
> searching on the internet and hitting these long complicatred
> solutions involving the database "shema". Surely there is a simple
> way of telling with one line of sql if a table exists or not???
> Thanks!
It's possible, but the implementation depends on the database you are using.
Jet databases have a MSysObjects table which can be queried for the database
schema. SQL Server has INFORMATION_SCHEMA views which can also be queried
for this information. I suspect Oracle databases have similar structures.
See:
http://www.aspfaq.com/show.asp?id=2112
HTH,
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.