cmd.CommandText = "SELECT dbid FROM master.dbo.sysdatabases where name = '" + databaseName + "'"; object DbID = cmd.ExecuteScalar(); if(DbID != null) //if database exists { //CHECK IF DATABASE NOT EMPTY , if not empty ,display message already exists. cmd.CommandText = "select count(*) from INFORMATION_SCHEMA.TABLES"; //this is what i have tried but its giving same count for all the database even if there is a empty db. object TCount = cmd.ExecuteScalar(); if(Convert.ToInt32(TCount) > 0) //if database is not empty { //return result -database exists; } }
SELECT COUNT(name) FROM sys.Tables
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)