Hi,
I'm using executenonquery to check the existence of table in the
database.
I tried two methods of queries, everything return -1 even though table
exists in database
Code as below
SqlConnection connection=new SqlConnection("Data Source=\LOCAL;
Initial Catalog=ff; Integrated Security=SSPI; Persist Security
Info=False; ");
connection.Open();
string tableExistsCheckQuery="SELECT * FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='resultsc'";
//string tableExistsCheckQuery="SELECT * FROM dbo.sysobjects WHERE
id =OBJECT_ID(N'[dbo].[resultsc]')AND OBJECTPROPERTY(id,
N'IsUserTable') = 1";
SqlCommand command=new
SqlCommand(tableExistsCheckQuery,connection);
int a=command.ExecuteNonQuery();
'a' always return -1 if table exists in data base or not
I tried changing the query as below
string tableExistsCheckQuery="SELECT * FROM dbo.sysobjects WHERE id
=OBJECT_ID(N'[dbo].[resultsc]')AND OBJECTPROPERTY(id, N'IsUserTable')
= 1";
its also returning -1.
Is there any mistake in my code?
Thanks,
Mani