alert before deleting sql databases through a winform application [closed]
I want that on a new installation of my .net winforms application, which uses sql server 2005 express , it would drop old databases if exist but before deleting them , it alerts that the databases are empty or not by showing a message box i.e. they contain tables or not , & then creates new databases.
so whats the way to do this?
You can run a SQL Statement similar to this
select 1 as DBExists from master.sys.databases where name = 'YourDatabaseNameGoesHere'
If the dataset has rows, then the database exists!
You can find the number of tables in it (to see if it is empty or not) by running this SQL
select COUNT (*) as NumTables from YourDatabaseNameGoesHere.INFORMATION_SCHEMA.TABLES
If the dataset has rows, then display a messagebox with the appropriate message and then if the answer is "Yes" then drop the database.
精彩评论