Function for check table is exist or not in sql database

Samirbhogayta
Posted by Samirbhogayta under Sql Server category on | Points: 40 | Views : 346
public int CheckTable(string TableName)
{
int i = 0;
string cmdText = @"IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME='" + TableName + "') SELECT 1 ELSE SELECT 0";
i = (int)ExecuteScalar(cmdText,CommandType.Text,null,null);
return i;
}

Using this function you can get 0 or 1 as return i result.

Comments or Responses

Login to post response