比如我从sql2000中存储过程生成的脚本代码,放到文本框中。点按钮后对sql 中 a  b  c 数据库存储过程更新。现在关键点是怎么在程序中执行脚本代码,没太搞明白。

解决方案 »

  1.   

    你把脚本当做sql语句直接执行看看
      

  2.   

    http://www.knowsky.com/345516.html
      

  3.   

    //当SQL直接执行bool Sqltest()
            {
                bool b = false;
                try
                {
                    string sql = "";
                    foreach (string line in TB_ReportSql.Lines)
                    {
                        sql += line + " ";
                    }
                    int k=new WebSqlRequest().ExecuteNonQuery(sql);//执行SQL
                    b = true;
                }
                catch  { }
                return b;
            }
      

  4.   

    修改存储过程 你在查询分析器里面怎么写脚本就怎么在程序里拼接字符串,然后用ADO.net、SqlCommand 调用ExecuteNonQuery() 方法执行,这样达不到效果么?
      

  5.   

    还可以使用sqlcmd:
            private string executeFromSqlCmd(string source, bool isFromFile)
            {
                string result = "";
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.ErrorDialog = true;
                p.StartInfo.FileName = "sqlcmd.exe";
                if (isFromFile)
                {
                    p.StartInfo.Arguments = "-W -i " + source;
                }
                else
                {
                    p.StartInfo.Arguments = "-W -Q \"" + source + "\"";
                }
                p.Start();
                result = p.StandardOutput.ReadToEnd();
                p.WaitForExit();
                return result;
            }