To use the initialization database in the project, you need to use the program call record. The two sections of code are the call method and the SQL. SQL file:
Private void setup () {dialogresult result; Result = MessageBox. Show ("when a new database is installed, the original database will be deleted. Are you sure you want to continue the installation! "," Warning ", messageboxbuttons. yesno); If (result = dialogresult. yes) {string sqlpath = "SQL. SQL "; system. diagnostics. process PS = new system. diagnostics. process (); PS. startinfo = new system. diagnostics. processstartinfo ("osql.exe", "-e-I" + sqlpath); // ps. startinfo. windowstyle = system. diagnostics. processwindowstyle. hidden; PS. start (); PS. waitforexit ();}}
IF exists (select name from master.dbo.sysdatabases where name='kj213')EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'kj213'GOUSE [master]GOdrop database [kj213]GOCreate DATABASE [kj213]GOCREATE LOGIN kj213 WITH PASSWORD = 'kj213';GOUSE kj213GOIF NOT EXISTS(select name from sysobjects where name='FC_WZ')CREATE TABLE [FC_WZ]([ID] [int] IDENTITY(1,1) NOT NULL,[WZID] [smallint] NOT NULL,[WZ] [nvarchar](30) NOT NULL,[UPFLAG] [varchar](1) NULL ) ON [PRIMARY]GO
As follows:
Then a DOS dialog box pops up...
Finally, open the database check result.
Data kj213 and login name kj213 are successfully created.
I don't know if there are other simple methods. Let's talk about it!