用什么方法可以执行这样的语句:(不能写存储过程。。)declare @a varchar(50) ,@b int set @a = '" + mlh + "' set @b = " + sxh + " update test1 set a=@a,@b= @b+1 ,b=@b,c=cast(a as varchar(50))+'-'+cast(@b as varchar(50)) where id f_nd='" + nd + "' and f_BGQX='" + qixian + "' and f_ZRZ='" + department + "'"
就是一条更新的语句咯
private void SetChange(string ip, string dbName, string user, string password, string sqlPath)
{
try
{
Process pr = new System.Diagnostics.Process();
pr.StartInfo.FileName = "sqlcmd.exe ";
pr.StartInfo.Arguments = string.Format("-U {0} -P {1} -d {2} -S {3} -i {4}", user, password, dbName, ip, sqlPath);
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.RedirectStandardOutput = true; pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pr.Start(); /* debug */
System.IO.StreamReader sr = pr.StandardOutput;
Console.WriteLine(sr.ReadToEnd());
pr.WaitForExit();
pr.Close();
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}
}