我现在是创建了一个控制台应用程序,然后:Process.Start(@"E:\a.sql");但是这样是打开a.sql 。并不是去执行a.sql 中的SQL语句。我想生成一个.exe ,我双击exe ,a.sql 中的SQL语句就可以自动执行。谢谢!PS:1.  a.sql 中的SQL语句很多,所以我不想用读取内容再执行SQL语句的办法。2.  我需要代码。如果没有现成的代码,那么思路也好。只是我对控制台应用程序不熟悉。3.  非常感谢。

解决方案 »

  1.   

    Process p=new Process(); 
    p.StartInfo.FileName="osql.exe"; 
    p.StartInfo.Arguments=String.Format("-U {0} -P {1} -S {2} -i {3}","sa","sa","","");   
    p.StartInfo.WindowStyle=ProcessWindowStyle.Hidden; 
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true; 
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden'
    p.Start();
        
    System.IO.StreamReader sr = p.StandardOutput;
    Console.WriteLine(sr.ReadToEnd());
    p.WaitForExit(); 
    p.Close(); 
      

  2.   

    using System;
    using System.IO;
    class DirectoryLister
    {
        public static void Main(String[] args)
        {
            string path = ".";
            if (args.Length > 0)
            {
                if (File.Exists(args[0])
                {
                    path = args[0];
                }
                else
                {
                    Console.WriteLine("{0} not found; using current directory:",
                        args[0]);
                }
            
            DirectoryInfo dir = new DirectoryInfo(path);
            foreach (FileInfo f in dir.GetFiles("*.exe")) 
            {
                String name = f. Name;
                long size = f.Length;
                DateTime creationTime = f.CreationTime;
                Console.WriteLine("{0,-12:N0} {1,-20:g} {2}", size, 
                    creationTime, name);
            }
        }
    }
      

  3.   

    调用 进程
    osql.exe 传参数
      

  4.   

    1L  , 谢谢,我感觉成功了80% 多,但是提示有错误啊。我.sql中的SQL语句可以全选执行的,但是.exe运行它的时候报错,说是*/这样的注释错误?能给解答一下吗?谢谢。2L 。 莫名其妙。。3L 。谢谢。能具体一些吗?