首先要在數(shù)據(jù)庫生成好的SQL腳本最前頭,加入如下語句: use master GO
if exists (select * from sysdatabases where name='mytest') drop database mytest GO
create database mytest GO
use mytest GO 注:其中“mytest”是要創(chuàng)建的數(shù)據(jù)庫名。
而程序的代碼如下: //---------------------------Create DB------------------------------------- //------------------------------------------------------------------------- //---File:frmCreateDB.cs //---Description:The main form file to create database using specific SQL file //---Author:Knight //---Date:Mar.18, 2006 //------------------------------------------------------------------------- //-------------------------{ Create DB }----------------------------------- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.SqlClient;