C # program call Code Generation Database

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.