473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SqlConnection question

Hi

how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not

Thank
Sam
Nov 22 '05 #1
6 1387
Sam

You could run a query against the sysobjects table in the databse you are connected to

The query could look something like this

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyTableName]') and OBJECTPROPERTY(id, N'IsUserTable') = 1

Hope this help

Nov 22 '05 #2
Sam

You could run a query against the sysobjects table in the databse you are connected to

The query could look something like this

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyTableName]') and OBJECTPROPERTY(id, N'IsUserTable') = 1

Hope this help

Nov 22 '05 #3
If you're already connected to a specific database you can use the
following query to determine if the table exists.

SELECT table_name FROM INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'

The other choice for table_type is 'VIEW'.

--Mary

On Sun, 18 Apr 2004 06:41:02 -0700, "Sam Johnson"
<an*******@discussions.microsoft.com> wrote:
Hi,

how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not?

Thanks
Sam


Nov 22 '05 #4
If you're already connected to a specific database you can use the
following query to determine if the table exists.

SELECT table_name FROM INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'

The other choice for table_type is 'VIEW'.

--Mary

On Sun, 18 Apr 2004 06:41:02 -0700, "Sam Johnson"
<an*******@discussions.microsoft.com> wrote:
Hi,

how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not?

Thanks
Sam


Nov 22 '05 #5
Hi Sam,

You could query system tables. but if you want to be generic, then use
OpenSchema method if ADO or GetOledbSchemaTable method if ADO.NET

http://support.microsoft.com/default...b;en-us;309488

--
Val Mazur
Microsoft MVP
"Sam Johnson" <an*******@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,

how can I test if a specific table on an SQL- Server (that I'm connected
to) exists or not?

Thanks
Sam

Nov 22 '05 #6
Hi Sam,

You could query system tables. but if you want to be generic, then use
OpenSchema method if ADO or GetOledbSchemaTable method if ADO.NET

http://support.microsoft.com/default...b;en-us;309488

--
Val Mazur
Microsoft MVP
"Sam Johnson" <an*******@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
Hi,

how can I test if a specific table on an SQL- Server (that I'm connected
to) exists or not?

Thanks
Sam

Nov 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: huzz | last post by:
I have a method that gets sqldatareader as shown below.. my question is how do i close the sqlconnection (objConn) object within this method? If i put the objconn.Close(); after the return then i...
0
by: Nayt Grochowski | last post by:
Does anyone see any problem with the loading a SqlConnection into the System.Web.HttpContextCurrent.Items collection in a Page's Constructor. Then Closing and Disposing of it the OnUnload method? ...
6
by: goodstart123 | last post by:
For example, the following code works fine without SqlConnection. Any Answer to the question? string connectionString = "server=YourServer; uid=sa; pwd=YourPassword;...
4
by: The Coolest Dolphin | last post by:
Hi all, I have a question/problem concerning usage of my sqlconnection throughout my program. In my main form (frmMain) I defined an sqlconnection (I've set the connection public so that I can...
13
by: MuZZy | last post by:
Hi, Just wanted to make sure i get it right: consider this class: // =========== START CODE ============= class Test { private SqlConnection con = null; public void Connect() { con = new...
11
by: Bob | last post by:
In our new .NET web applications, we try to limit the use of SqlConnection to just one instance per page, even if there are multiple accesses to various queries. The thinking behind is that this...
2
by: StephenRichter | last post by:
I have SqlServer loaded on my w2k system. The freeby I just downloaded from MS. Within WebMatrix I created a database. called it "WebMatrix" In WebMatrix I connect to the database. server:...
1
by: jinfeng_Wang | last post by:
hi, I have a question about the difference between SqlConnection.IDisposable.Dispose() and SqlConnection.Dispose(). Both of them realize the function of releasing the connection to the...
4
by: Victor | last post by:
Hi Guys I have a problem here. I want to improve the performance for a website. When I looked into the system, I have found that the system made the "SqlConnection Object" static. That mean only...
4
by: =?Utf-8?B?dGhlIGZyaWVuZGx5IGRpc3BsYXkgbmFtZQ==?= | last post by:
Hello, I am planning to use three databases on the local SQL Server. DB1 will be for App1, DB2 for App2, and DB3 will hold tables, that both, App1 and App2 need to access. With applications...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.