如果有存储过程,直接点击button时执行相关存储。如果没有存储过程,单独放进一个文本文件吧,要执行的时候读文件传sql过去!不过怎么感觉这是在多此一举啊。后缀为sql的文件就算是查询分析器打开也不是会自动执行的。你还是得调用执行的命令对象。和一般写法没多大区别的啊。

解决方案 »

  1.   

    我的网站现在卡在这里了 其它功能不好动 只能在程序中后台处理.sql脚本的执行了
      

  2.   

    就是说我现在有一个aaa.sql的脚本文件 我想在.net的程序中把它给执行了 导入其中的数据到已经建好的数据库中 我也知道执行MySQl.exe 关键是线在不想这样做
      

  3.   

    你不调用执行sql的命令对象好像是做不到的吧。
    那我就实在是没办法了。
      

  4.   

    string s = "--host=localhost --user=root --password=root lanqiu -r \"" + string.Format("{0}", @"d:\dabao.sql") + "\"";System.Diagnostics.Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe", s); 这个是导出的执行语句 导入得怎么弄啊 其中 用户root 密码root 数据库lanqiu 导出路径d:\dabao.sql
      

  5.   

    楼主,能不能换种方式,把要执行的SQL语句放到页面的PageLoad中,要执行哪句SQL就打开那个窗口,执行完返回原来窗口
      

  6.   

    直接执行*.SQL很难,SQL语句是可以的,或者写成存储过程再执行
      

  7.   

    不懂,没见过怎么执行.sql文件呢,来学习一下
      

  8.   

    http://topic.csdn.net/u/20080730/10/7373a572-8ec8-40d3-bc8e-eac092b3d78c.html?seed=1111677487
    你看看这里的贴子,好像是可以解决的。
      

  9.   

    还不如将AAA.SQL写入一个存储过程。。然后执行存储过程
      

  10.   

    关键是客户提供过来的是.sql文件 在我这里汇总啊 各个.sql文件都不一样 我要写多少个存储过程啊
      

  11.   

    必须在程序里运行的话,考虑12楼的建议把
    要么创建一个批处理文件,只要有新的.sql文件,就把批处理文件更新,然后执行批处理文件。
    OSQL..命令好像是执行.sql文件的。好久没弄     记不太清楚
      

  12.   

    using System;
    using System.Data;
    using System.Collections;
    using System.Xml;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
     
    namespace sym
    {
        public class symConsole
        {
            [STAThread]
            static void Main(string[] args)
            {
                string sqlQuery = "osql.exe /uSa /p123 /s192.192.132.229 /dNorthWind /i yoursql.sql";
                string strRst = ExeCommand(sqlQuery);
                Console.WriteLine(strRst);
                Console.ReadLine();
            }
            
            public static string ExeCommand(string commandText)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                string strOutput = null;
                try
                {
                    p.Start();
                    p.StandardInput.WriteLine(commandText);
                    p.StandardInput.WriteLine("exit");
                    strOutput = p.StandardOutput.ReadToEnd();
                    p.WaitForExit();
                    p.Close();
                }
                catch(Exception e)
                {
                    strOutput = e.Message;
                }
                return strOutput;
            }
        }
    }对于osql命名的参数如下:
    =====================
     
    用法: osql              [-U login id]          [-P password]
     [-S server]            [-H hostname]          [-E trusted connection]
     [-d use database name] [-l login timeout]     [-t query timeout]
     [-h headers]           [-s colseparator]      [-w columnwidth]
     [-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
     [-L list servers]      [-c cmdend]            [-D ODBC DSN name]
     [-q "cmdline query"]   [-Q "cmdline query" and exit]
     [-n remove numbering] [-m errorlevel]
     [-r msgs to stderr]    [-V severitylevel]
     [-i inputfile]         [-o outputfile]
     [-p print statistics] [-b On error batch abort]
     [-X[1] disable commands [and exit with warning]]
     [-O use Old ISQL behavior disables the following]
     [-? show syntax summary]
      

  13.   

    大哥 我说了 我的库是 MYSql 不是Sql Server
      

  14.   

    不想用查询,把.sql写成.bat,执行一下.哈哈,莫名其妙的问题!
      

  15.   

    string s=@"mysql -uroot -pyourpassword yourdatabasename < c:\aaa.sql";System.Diagnostics.Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysql.exe", s); 
      

  16.   

    不太明白你的意思,我想你可以用MVC的方式做