我已经把view1导出到了1.sql,怎么用Adoquery导入到数据库?
我的数据库是SQL 2K

解决方案 »

  1.   

    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.LoadFromFile(1.txt);
    adoquery1.execsql;
      

  2.   

    错误1: 不能含有“GO”
    错误2: CREATE 必须放前面
      

  3.   

    var
      s:string;
      sqltext : string;
      sqlfile : TextFile;
    begin
      if OpenDialog1.Execute then
      begin
        AssignFile(sqlfile, OpenDialog1.FileName);
        FileMode := 0;
        Reset(sqlfile);
        try
          ADOConnection1.BeginTrans;
          while not eof(sqlfile) do
          begin
            Readln(sqlfile, s);
            sqltext:=s;
            while (not eof(sqlfile)) and 
            (uppercase(trim(s))<>'GO') do
            begin
              Readln(sqlfile, s);
              if (uppercase(trim(s))<>'GO') then
                sqltext:=sqltext+' '+s;
            end;
            adoquery1.Close;
            adoquery1.SQL.Clear;
            adoquery1.SQL.Add(sqltext);
            adoquery1.ExecSQL;
          end;
      

  4.   

    //执行一个SQL角本文件,文件只能是ANSI编码的。
    //如果文件是UNICODE编码的话,则会乱码。
    var
      s:string;
      sqltext : string;
      sqlfile : TextFile;
    begin
      if OpenDialog1.Execute then
      begin
        AssignFile(sqlfile, OpenDialog1.FileName);
        FileMode := 0;
        Reset(sqlfile);
        try
          ADOConnection1.BeginTrans;
          while not eof(sqlfile) do
          begin
            Readln(sqlfile, s);
            sqltext:=s;
            while (not eof(sqlfile)) and 
            (uppercase(trim(s))<>'GO') do
            begin
              Readln(sqlfile, s);
              if (uppercase(trim(s))<>'GO') then
                sqltext:=sqltext+' '+s;
            end;
            adoquery1.Close;
            adoquery1.SQL.Clear;
            adoquery1.SQL.Add(sqltext);
            adoquery1.ExecSQL;
          end;
          CloseFile(sqlfile);
          ADOConnection1.CommitTrans;
          application.MessageBox('SQL角本完成!',
            '提示',MB_OK+MB_ICONINFORMATION);
        except
          raise exception.Create('SQL角本执行失败!');
          ADOConnection1.RollbackTrans;
        end;
      end;
    end;
    其中:ADOConnection1,adoquery1,OpenDialog1都是窗口中放置的控件。可以将之设为局部变量,在本函数内创建和消毁。