473,499 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking fro Table existince in SQL2005

HI all,

I want check for the existence of a particular table in sql. Then branch
code on the result
I was thinking of a command something like:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[tempimport]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
But dont know how to get a return value to my C# app so that I can make
decisions in my code

Thanks
Robert
Jul 8 '06 #1
2 1412

"Robert Bravery" <me@u.comwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...
HI all,

I want check for the existence of a particular table in sql. Then branch
code on the result
I was thinking of a command something like:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[tempimport]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
But dont know how to get a return value to my C# app so that I can make
decisions in my code
Just use what you have without the IF EXISTS something like

sql.CommantText = "SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[tempimport]')AND OBJECTPROPERTY(id, N'IsUserTable') = 1";
int a = sql.ExecuteNonQuery();

Then "a" should be 1 or more :)
Jul 8 '06 #2
Robert Bravery wrote:
HI all,

I want check for the existence of a particular table in sql. Then branch
code on the result
I was thinking of a command something like:
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[tempimport]')
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
But dont know how to get a return value to my C# app so that I can make
decisions in my code
Better use information_schema view. Something like this (SQL syntax tested):

sqlCommand.CommandText = @"SELECT
CASE
WHEN EXISTS (SELECT 1 FROM information_schema.tables
WHERE table_type = 'base table' AND table_name = 'tempimport')
THEN 1
ELSE 0
END;";

bool itExists = (1 == (int)sqlCommand.ExecuteScalar());
Jul 8 '06 #3

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

Similar topics

2
1786
by: ad | last post by:
The user of my asp.net program use Sql2005 or Sql2005 express as database, both are possible. I have try both version of data base, I found: If I use Sql2005 express, the Data Source in...
2
1050
by: ad | last post by:
Hi, As title, After I install Sql2005 SepCTP, can I install VS2005 Beta2 in the same machine?
22
6386
by: Mal Ball | last post by:
I hope I have the right forum for this question. I have an existing Windows application which uses a SQL Server database and stored procedures. I am now developing a web application to use the same...
7
4335
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
1
2722
by: r1100r98 | last post by:
I am having a problem moving the data from a datatable to the SQL2005 table (using VB2005). See code below. The SQL2005 table is empty, the datatable is being filled from a text file, not from...
5
3894
by: Mike | last post by:
I'm having trouble accessing SQL2005 Standard Edition as a second instance of SQL Server where the first instance is SQL 2000 Enterprise Edition. I installed SQL 2005 as a named instance...
2
3363
by: Roger | last post by:
I've got two tables in sql2005 which have an 'ntext' field when I linked the first table in access97 last week using an odbc data source the access-field type was 'memo' when I link the 2nd...
1
1174
by: Chronos979 | last post by:
Hi. I need some help. Yesterday I tryed to link a table from our SQL2005 server into Access. I Used the SQL Native Client. Connection test was Succeeded, and then i was linked the table. It's...
0
1988
by: nic829 | last post by:
Hi, I was upgrading a instance from SQL2000 to SQL2005. During SQL2005 setup I accidently allow the files to be installed in C drive, but I should have them all installed in D drive. My databases...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7178
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
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.