Solved

Check if SQL table exists from vb.net

Posted on 2014-02-23
2
887 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

729 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