Execute the batch processing file (. bat) in C # And perform database operations,
Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using System. configuration; using System. data. sqlClient; using System. data; using System. diagnostics; namespace Sample2 {class Program {static void Main (string [] args) {Process proc = null; try {/** autorun. bat file content osql-S 127.0.0.1-d DataSample-U sa-P 1234567890-I C: \ test. SQL */string targetDir = string. format (@ "C: \"); proc = new Process (); proc. startInfo. workingDirectory = targetDir; proc. startInfo. fileName = "autorun. bat "; proc. startInfo. arguments = string. format (""); // this is argument proc. startInfo. createNoWindow = true; proc. startInfo. windowStyle = ProcessWindowStyle. hidden; // The DOS window is not displayed here. It is feasible to use proc. start (); proc. waitForExit (); Console. readKey ();} catch (Exception ex) {Console. writeLine ("Exception Occurred: {0}, {1}", ex. message, ex. stackTrace. toString ();}/* test. SQL content USE [DataSample] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo]. [Area] ([AreaId] [int] IDENTITY (1, 1) not null, [AreaName] [nvarchar] (50) NULL, [CityId] [int] NULL, CONSTRAINT [PK_Area] primary key clustered ([AreaId] ASC) WITH (PAD_INDEX = OFF, expiration = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] GO */}}}