我还未学过Delphi,我想向各位请教以下问题:
我想用ADO连接Oracle数据库(用户名:user,密码:pass,server:server),执行一个SQL语句("select a,b,count(c) from d where to_char(o_date,'yyyymmdd') between "+the_date +"group by a,b"),the_date从窗体上的DropDownListBox控件选出,然后将结果写入一个文本文件result.txt,字段间用逗号分开,写完一行后换行,直至写完所有数据,然后用系统中.txt文件默认关联的程序打开该文件。
我想这个程序不太难,我想把他作为学习这门语言的开始,请不吝赐教提供源码。

解决方案 »

  1.   

    TO: iceriver521(野兽王子)
    讲个大概也好
    我会用VB作,但是对Delphi 语法不熟,不知怎样下手
      

  2.   

    1,用Database控件,设置connect属性,连接数据库
    2,用Adoquery控件,connect设成Database,设置SQL属性,就是查询用的SQL语句,查出结果集
    3,一条一条选出,存为文件,
    4,调用系统程序,打开刚才的即使本文件!
      

  3.   

    第一步是用ADOConnection,设置连接字符串!
      

  4.   

    对,主要是设置conectstring!跟vb没什么大区别
      

  5.   

    不好意思,一直没时间来看,谢谢你们的指导
    我现在不知该如何再循环写数据时判断记录集的结尾,就象eof
    我该怎么作呢?
      

  6.   

    直接就能记录数据
    DBGrid+ADOQuery
    var 
       mm:String;
    begin
       mm:=ADOQuery1.FieldByName('字段名').AnString;
    end;
    ADOQuery自动记录光标位置。
      

  7.   

    你可以用 while not adoquery.eof  do 
             begin
               ;//   
             end;
      

  8.   

    你今天到来了,就用这个最方便了,
    while not adoquery.eof  do 
    begin
      mm:=ADOQuery1.FieldByName('字段名').AnString;
      adoquery.Next;          
    end;
      

  9.   

    AssignFile(fText,'LOGIN.Txt');
       Reset(fText);
       while not Eof(fText) do
         begin
         Readln(fText,strLine);
         strLine:=Trim(strLine);
         Combo_user.Items.Add(strLine);
           if combo_user.Items.Count=10 then
           begin
           break;
           end;
         end;
         CloseFile(fText);
       //初始化COM_USER数据   从文本中读出USER
    //从COMBOBOX中写入
                    for i:=0 to combo_user.Items.Count do
                      begin
                        if trim(Combo_user.Text)=trim(combo_user.Items.Strings[i])  then
                          begin
                          flag:=true; //意味着存在相同的字段;
                          end;
                      end;
                    end;
                  if not flag then      //意味着不存在相同的字段;
                    begin
                    combo_user.Items.Insert(0,trim(combo_user.Text));
                    end;
                    for j:=1 to combo_user.Items.Count do
                    begin
                    combo_user.Items.SaveToFile('login.txt');
                    end;
      

  10.   

    我用下面的程序怎么读不到数据啊?
    另外最近CSDN太难上了,总出500错,愁死我了:(procedure TForm1.Button1Click(Sender: TObject);
    begin
      //adoquery1.sql.Add  ('select deptno from dept_info');
      adoquery1.ExecSQL;
      while not adoquery1.eof  do
      begin
        mm:=mm+ADOQuery1.FieldByName('deptno').AsString;
        adoquery1.Next;
      end;
      Memo1.Lines.Add(mm);
      //fText:='c:\test.txt';
      //AssignFile(Output, 'c:\test.txt');
      //Rewrite(Output);
      //write (mm);
      //CloseFile('c:\test.txt');
      showmessage('ok');
    end;
      

  11.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      //adoquery1.sql.Add  ('select deptno from dept_info');
      adoquery1.Open;//改这儿
      while not adoquery1.eof  do
      begin
        mm:=mm+ADOQuery1.FieldByName('deptno').AsString;
        Memo1.Lines.Add(mm);
        adoquery1.Next;
      end;
        //fText:='c:\test.txt';
      //AssignFile(Output, 'c:\test.txt');
      //Rewrite(Output);
      //write (mm);
      //CloseFile('c:\test.txt');
      showmessage('ok');
    end;