How to determine if database and table exists using ADO.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sampalmer21
    New Member
    • Feb 2008
    • 11

    How to determine if database and table exists using ADO.NET

    Is there a way I can find out if a database I have created exists in the sql server using ado.net methods? How about determining if a table exists, or any other database object for that matter?

    The reason I wish to know this is so that my application can recreate the database or tables if they get deleted by the user.
  • saran23
    New Member
    • Mar 2008
    • 28

    #2
    Originally posted by sampalmer21
    Is there a way I can find out if a database I have created exists in the sql server using ado.net methods? How about determining if a table exists, or any other database object for that matter?

    The reason I wish to know this is so that my application can recreate the database or tables if they get deleted by the user.

    Hi,
    use this Query in the sqlcommand and check whether the table exists or not,
    U can use a SP or a direct query in Sqlcommand,
    The query returns a boolean value,

    Here goes the query
    Code:
    if exists (select * from sysobjects where xtype='u' and name='tablename')
    Here u denotes user table

    Thanks
    Saravanan

    Comment

    Working...