?
Solved

Check if SQL table exists from vb.net

Posted on 2014-02-23
2
Medium Priority
?
974 Views
Last Modified: 2014-02-23
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
0
Comment
Question by:SweetingA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 2000 total points
ID: 39881055
cmd = New SqlCommand("SELECT OBJECT_ID('temptbl_Stops')")

If the result is non-null than the table exists.
0
 

Author Closing Comment

by:SweetingA
ID: 39881084
Excellent thankyou, watch the next post, i am sure it will be easy for you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question