Check if SQL table exists from vb.net

I need to check an SQl table exists from vb.net

I have seen lots of blogs but i can not get any of them to work in my code.

I have this which does not error, but i need to know what to add to do the check and drop the table if it exists

As SqlConnection = New SqlConnection(myserver details)
Dim cmd As SqlCommand
Dim con
 cmd = New SqlCommand("SELECT * FROM SYS.OBJECTS WHERE TYPE = 'u' AND NAME = 'temptbl_Stops'", con)
If con.State = ConnectionState.Closed Then con.Open()
cmd.ExecuteNonQuery()

Any help most welcome, i am a total novice as you have probably guessed
SweetingAAsked:
Who is Participating?
 
Brian CroweConnect With a Mentor Database AdministratorCommented:
cmd = New SqlCommand("SELECT OBJECT_ID('temptbl_Stops')")

If the result is non-null than the table exists.
0
 
SweetingAAuthor Commented:
Excellent thankyou, watch the next post, i am sure it will be easy for you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.