المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How can I check if a table exists?



C# Programming
11-13-2009, 06:40 PM
can anyone help?

I tried to google out the solution but none of the answers I found was non proper for C#.

I've a MS SQL Database (Compact Edition(this is not an issue here))

I want to check if a table exists, what should I do?

I found an SQL statement for this


IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') AND type in (N'U'))

but I could not figure out how to use this in C#

My first idea is=

string command2 = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') AND type in (N'U'))"
SqlCeCommand com2 = new SqlCeCommand(command2, conn);

Where should I look if it returned 1 or 0?