> How can i check in code-behind (VB) whether that table (e.g. table 'dan'
> exists)?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
> Since you don't mention what back-end RDBMS you're using, I'll assume it's
> SQL Server...
D'oh - apologies - I didn't read the title closely enough...!

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
[...]
> SELECT COUNT(*) FROM sys.tables WHERE [name] = 'dan' AND [type] = 'U'
[...]
> There must be at least half a dozen other ways of doing this...
A better one IMO is to use the INFORMATION_SCHEMA views.
\\\
select *
from INFORMATION_SCHEMA.Tables
where TABLE_NAME = 'dan'
///
This is an ANSI standard (http://en.wikipedia.org/wiki/Information_Schema).
No directly accessing system tables, no "magic" codes (why does 'type' need
to be set to 'U'?), won't break on future versions of SQL Server and also
works on other RDBMSs.
There are lots of other INFORMATION_SCHEMA views that give access to
columns, views, constraints, stored procedures, etc. To see them all, take a
look at the views that are defined against the master database on your
server.
HTH,

Signature
(O)enone
Mark Rae [MVP] - 08 Jul 2007 10:46 GMT
> This is an ANSI standard
> (http://en.wikipedia.org/wiki/Information_Schema).
Indeed.
> won't break on future versions of SQL Server
You can't know that for sure...
> and also works on other RDBMSs.
Apart from the ones which don't support it, e.g. Oracle, Jet etc:
http://www.databasejournal.com/news/article.php/3686366
http://www.thescripts.com/forum/thread199615.html

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
(O)enone - 08 Jul 2007 12:32 GMT
>> won't break on future versions of SQL Server
>
> You can't know that for sure...
Maybe not, but I think it's a much safer bet than selecting from system
tables. If MS decide to reorganise the internals of SQL Server (and I'm sure
it's a possibility!), I would certainly hope they would ensure that the
INFORMATION_SCHEMA views keep working. And if not, it would be much easier
to modify they to maintain their previous functionality than to fix every
bit of code that selected from the system tables directly.

Signature
(O)enone