var
  Form5: TForm5;
  state: integer;implementation{$R *.dfm}procedure TForm5.RadioGroup1Click(Sender: TObject);
begin
edit1.Clear;
    case RadioGroup1.ItemIndex of
    0:   begin            
            state:=0;
          end;
    1:   begin          
            state:=1;
          end;
          
end;
end;procedure TForm5.Button1Click(Sender: TObject);
begin
query1.SQL.Clear;      if state=0 then
      begin
      query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
      query1.SQL.Add('from student,course,sc');
      query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
      query1.Prepare;
      query1.params[0].asstring:=edit1.text+'%';
      query1.UnPrepare;
      end;      if state=1 then
      begin
       query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
      query1.SQL.Add('from student,course,sc');
      query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
      query1.Prepare;
      query1.params[0].asstring:=edit1.text+'%';
      query1.UnPrepare;
      end;      query1.Open;
end;end.
我在三个表student(....) course(...) 还有sc(....)表    意思想查综合信息.里面有student,course, sc表里的东西
但我上面上样写却行不通.大家能不能帮我看下错在哪里???

解决方案 »

  1.   

    不知道你想表达的是不是这个意思:  if state=0 then
          begin
          query1.SQL.Add
    ('select sc.sno,student.sname,student.sdept,course.cname,student.grade,student.ssex,student.sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';//还有,我没发现你的参数在哪里
          query1.UnPrepare;
          end;
      

  2.   

    procedure TForm5.Button1Click(Sender: TObject);
    begin
    query1.SQL.Clear;      if state=0 then
          begin
          query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';
          //query1.UnPrepare;
          end;      if state=1 then
          begin
           query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';
         // query1.UnPrepare;
          end;      query1.Open;
    end;
    这样如何?
      

  3.   

    1,没有看到你的参数
    DELPHI 可以这样写:SELECT * FROM STUDENTD WHERE STU_ID=:ID
    其中ID是参数
    然后给参数赋值 QUERY1.PARAMETERS.PARAMETERSBYANME('ID').VALUE:='1';2,不要使用QUERY1.UNPREPARE,实在是没有必要
      

  4.   

    谢谢大家的关注它的错误提示如下:
    project project1.exe raised exceptin class elisterror with message "list index out of bounds(0)'.process stopped ,use step or run to continue 
      

  5.   

    明显而简单的错误。sql语句中必须有如 :varname的格式,才可以调用参数(varname表示参数名称)
    如:xymao123() 所写
      

  6.   

    if state=0 then
          begin
          query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where course.cno=sc.cno and sc.sno=student.sno like :num');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';      end;      if state=1 then
          begin
          query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno like :no ');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';      end;      query1.Open;
    end;
    我后来这样写了参数但还是不行
    不知道为什么???/
      

  7.   

    if state=0 then
          begin
          query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where course.cno=sc.cno and sc.sno=student.sno like :num');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';      end;      if state=1 then
          begin
          query1.SQL.Add('select sc.sno,sc.cno,sname,sdept,cname,grade,ssex,sage');
          query1.SQL.Add('from student,course,sc');
          query1.SQL.Add('where sc.sno=student.sno and course.cno=sc.cno like :no ');
          query1.Prepare;
          query1.params[0].asstring:=edit1.text+'%';      end;      query1.Open;
    end;
    我后来这样写了参数但还是不行
    不知道为什么???/
      

  8.   

    query1.SQL.Add('where course.cno=sc.cno and sc.sno=student.sno like :num');
    ---------------------------------------------------------------------------
    like :num
    前面应该有字段名吧 一般是 field1 like %a%