Tuesday, September 8, 2015

Function for check table is exist or not in sql database

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;
        }

No comments: