我做多条件查询,在一个窗口上输入条件,在另外一个窗口上显示
下面是我的程序,各位看看有什么错误,有好的建议也不妨提出来,候教了!!procedure TForm5.Button1Click(Sender: TObject);begin
    begin
     with form6 do
          begin
            adoquery1.close;
            adoquery1.sql.clear;
            adoquery1.sql.add('select * from 教师表,课程表');
            adoquery1.SQL.Add('where 教师表.课程序号=课程表.课程序号号');            if edit1.Text<>'' then
            adoquery1.SQL.Add('and 教师表.教师编号:='''+edit1.Text+'''');
            if edit2.Text<>'' then
            adoquery1.SQL.Add('and 教师表.教师姓名:='''+edit2.Text+'''');
            if combobox1.Text<>'' then
              begin
              adoquery1.SQL.Add('and 教师表.所属院系=:所属院系');
              adoquery1.Parameters.ParamByName('所属院系').Value:=combobox1.Items.IndexOf(combobox1.Text);
              end ;
            if combobox2.Text<>'' then
              adoquery1.SQL.Add(' and 课程表.课程名称:='''+combobox2.Text+'''');
             adoquery1.ExecSQL;                  end;
     form6.Show;
     end;end;

解决方案 »

  1.   

    adoquery1.ExecSQL;应为open
    最好调试一下
      

  2.   

    adoquery1.ExecSQL改为open,ExecSQL‘一般’在不返回记录集的时候使用,如删除,插入或者修改,open则在返回记录集的时候使用edit1.text改为trim(edit1.text),具体什么错误最好把错误或者源码贴出来大家好帮你调试
      

  3.   

    除了楼上所说的外
    还要注意每个add语句里都第一个字符都要是空格
    否则
    比如说你的第一句“课程表”和where就连在一起了
    会造成语法错误
      

  4.   

    对,还有你的代码不太规范!
    select * from 教师表 a ,课程表  b 
    where a.课程序号=b.课程序号号
      

  5.   

    adoquery1.SQL.Add('and 教师表.所属院系=:所属院系');
                  adoquery1.Parameters.ParamByName('所属院系').Value:=combobox1.Items.IndexOf(combobox1.Text);
    combobox1.Items.IndexOf(combobox1.Text):这个得到的值是integer的!改成:adoquery1.sql.add('and 教师表.所属院系='''+combobox1.text);
      

  6.   

    ctrl+F8,点中要需跟踪的代码首尾两行变红色,然后运行程序,F8单步执行
      

  7.   

    1.太乱
    2.在SQL语句中 判断条件用 "=",而不是":="
    3.adoquery1.open返回查询结果,adoquery1.ExecSQL不返回结果
    TForm5.Button1Click(Sender: TObject);
    var
       Sql:String;
    begin
       Sql:='select * from 教师表,课程表 where (教师表.课程序号=课程表.课程序号) '
       if edit1.Text<>'' then
          SQL:=Sql + 'and (教师表.教师编号='+ edit1.Text +') ';
       if edit2.Text<>'' then
          SQL:=Sql +'and (教师表.教师姓名='+edit2.Text+') ';
       if combobox1.Text<>'' then
          SQL:=Sql +'and (教师表.所属院系='+combobox1.Text+') ';
       if combobox2.Text<>'' then
          SQL:=Sql +'and (课程表.课程名称='+combobox2.Text+')';
       if form6 = nil then
       begin
         Application.CreateForm(Tform6, form6);
         with form6 do
         begin
           adoquery1.close;
           adoquery1.sql.clear;
           adoquery1.sql.add(SQL);
           adoquery1.open;
         end;     form6.show;
       end
       else
       begin
       with form6 do
       begin
           adoquery1.close;
           adoquery1.sql.clear;
           adoquery1.sql.add(SQL);
           adoquery1.open;
       end;
       form6.Show;
     end;end;
      

  8.   

    :)
    说话的真多,不过我觉得NamasAmitabha(银雨辰)中的了!
    应该可以结了
    支持一下!
    --------------------------------------
    看见了么,
    那支蛾子,
    正飞向太阳,
    那就是我!
    --------------------------------------
      

  9.   

    我考,还要麻烦你们,我们组长一定要所属院系是integer类型的,怎么办,上面的程序怎么改
    只要求出在所选院系在下拉菜单中的位置即可,是不是使用items.indexof的属性啊,各位,能不能告诉我怎么做,直接在银雨辰上的程序改好了
      

  10.   

    if combobox1.Text<>'' then
          SQL:=Sql +'and (教师表.所属院系='+inttostr(combobox1.Items.IndexOf(combobox1.Text))');
      

  11.   

    if combobox1.Text<>'' then
       SQL:=Sql +'and (教师表.所属院系='+inttostr(ComboBox1.ItemIndex)+') ';