Using System;
Using System.Diagnostics;
Using System.Windows.Forms;
Namespace WindowsFormsApplication1
{
public partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
Parameters
string[] args = new string[5];
Args[0] = "-U" + txtusername.text; User name
ARGS[1] = "-P" + txtpassword.text; User password
ARGS[2] = "-S" + txtserver.text; Server
ARGS[3] = "-D" + txtdatabase.text; Database
ARGS[4] = "-I" + AppDomain.CurrentDomain.BaseDirectory + "Install.sql"; SQL Script Path
Perform
TextBox1.Text = CommandLine ("Osql.exe", args);
}
#region invoking command-line tools
<summary>
Invoking command-line tools
</summary>
<param name= "name" > Command line tool name </param>
<param name= "args" > Optional command line Parameters </param>
<remarks> Note: All command-line tools must be saved in the System32 folder </remarks>
<returns></returns>
private string CommandLine (string name, params string[] args)
{
Return CommandLine (Name, "", args);
}
<summary>
Invoking command-line tools
</summary>
<param name= "name" > Command line tool name </param>
<param name= "WorkingDirectory" > set working directory </param>
<param name= "args" > Optional command line Parameters </param>
<remarks> Note: All command-line tools must be saved in the System32 folder </remarks>
<returns></returns>
private string CommandLine (string name, String workingdirectory, params string[] args)
{
String returnvalue = "";
using (Process commandline = new process ())
{
Try
{
CommandLine. Startinfo.useshellexecute = false;
CommandLine. Startinfo.createnowindow = true;
CommandLine. Startinfo.windowstyle = Processwindowstyle.hidden;
CommandLine. Startinfo.redirectstandardoutput = true;
CommandLine. Startinfo.filename = name;
CommandLine. Startinfo.workingdirectory = WorkingDirectory;
Add command line arguments
if (args. Length > 0) commandline. Startinfo.arguments = string. Join ("", args);
CommandLine. Start ();
CommandLine. WaitForExit ();
returnvalue = commandline. Standardoutput.readtoend ();
CommandLine. Close ();
}
Catch
{
CommandLine. Dispose ();
Throw
}
}
Return returnvalue;
}
#endregion
}
}
. NET call Osql.exe Execute SQL script to create tables and stored procedures