how can i check if a table in sql server exists

vagelis

Member
Joined
Nov 7, 2009
Messages
8
Programming Experience
Beginner
hello everyone i am an new member here..

my problem is tha i want to know if a database table in sql server exists
i want to do this because i want to avoid an exception of select from a table tha doesnt exist

i use this code

Dim con As SqlConnection = New SqlConnection(Session("DBConString"))
Dim drw As SqlDataReader
Dim mycommandw As New SqlCommand("IF EXISTS (SELECT name FROM sysobjects WHERE name = 't_text' AND type = 'U') select text_caption from t_text where text_id=1", con)
con.Open()
drw = mycommandw.ExecuteReader()
prosopikaminimata.Text = drw(0)


and the exception message i reseave is(translated from greek)

"the read try is not valid because no data exist"

have anyone an idea??
 
Drop the If Exits and just use
VB.NET:
Expand Collapse Copy
Select NAME From SysObjects Where xType='u' And Name = 't_text'
You can also do a
VB.NET:
Expand Collapse Copy
Select count(*) from sysobjects where name = 't_text'
 
Back
Top