|
自己创建了个.sql的脚本文件,在C#中调用执行,初学,不知问题出在何处,大神详解,谢谢!代码如下:
private void buttonCreate_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "osql.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string Path = Application.StartupPath.ToString();
string Parameter = "osql.exe -U " + "sa" + " -P " + "123455" + " -S " + "PC-20130318ZRGN" + " -i " + Path + @"..\temp.sql";
try
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
p.Start();
p.StandardInput.WriteLine(Parameter);
p.StandardInput.WriteLine("exit");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
p.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
this.Close();
}
}
|
|