用dbgride吧query查询的结果显示出来不就行了啊?

解决方案 »

  1.   

    你这样查询只是把符合你的记录查找出来,不可能定位的要么重新用LOCATE 定位吧!
      

  2.   

    1、最好不用COUNT去判断,有时候有问题,用query1.IsEmpty判断比较好;
    2、已经指到了你查到记录的记录集第一条数据,可以用query1.FieldByName('a').As....去访问。
      

  3.   

    在form3.query1.Open;后面加入
     form3.query1.first;即指向你所查找的数据集的第一条记录位置。
      

  4.   

    rqcong() 
    你的意思是改成
    nearname:=trim(edit1.text);
    form3.query1.sql.clear;
    form3.query1.sql.add('select * from fcz where name like ''%'+nearname+'%''');
    form3.query1.Open;if not form3.query1.isempty then
    begin
    form3.query1.first;
    application.messagebox('已找到记录!','查询成功');
    end
    else
    begin
    application.messagebox('抱歉,记录不存在!','查询失败');end;
    end;
    还是不行,只定位在当前记录,并没有移到query查到的第一条记录上去,是不是我查询语句有错?????
      

  5.   

    请问用locate如何定位?????
      

  6.   

    我是用dbedit来显示记录的
    我用findkey,如果查到了就能够显示查到的记录
    但是复杂查询的话就要用sqlbegin
    form3.fczTable.indexfieldnames:='sfznum';
    if form3.fcztable.Findkey([edit1.text]) then
    BEGIN
    form4.close;
    application.messagebox('已找到记录!','查询成功');
    end
    else
    beginapplication.messagebox('抱歉,记录不存在!','查询失败');
    end;
    end;这个就没有问题,查到了马上就在dbedit里显示了
    用了query就不能显示查到的记录了
      

  7.   

    nearname:=trim(edit1.text);
    form3.query1.sql.clear;
    form3.query1.sql.add('select * from fcz where name like ''%'+nearname+'%''');
    form3.query1.Open;
    recount:=form3.Query1.RecordCount;
    if recount>=1 then
    begin
    form3.query1.locate('字段名',nearname,[loPartialKey]);
    edit1.text:=inttostr(recount);
    application.messagebox('已找到记录!','查询成功');
    end
    else
    begin
    application.messagebox('抱歉,记录不存在!','查询失败');end;
    end;
      

  8.   

    Tine2() 
    form3.query1.locate('字段名',nearname,[loPartialKey]);
    在这一句有两个错误了
    [Error] Unit4.pas(63): Undeclared identifier: 'loPartialKey'
    [Error] Unit4.pas(63): Incompatible types: 'TLocateOption' and 'Integer'
      

  9.   

    奇怪,我就按照和你几乎一样的代码就查询到了所要的结果,而且在DBGrid中也自动定位到了查询出来的第一条记录,你的DBGrid是不是某些属性设置有问题,例如DataSource.
      

  10.   

    这个东东简单,一般都是用Locate来定位记录的。
    具体怎么用可以查一查帮助嘛。
      

  11.   

    [Error] Unit4.pas(63): Undeclared identifier: 'loPartialKey'
    [Error] Unit4.pas(63): Incompatible types: 'TLocateOption' and 'Integer'这段我解决了,就是没有在use里加db
    但是还是不能定位过去,能不能讲清楚些是哪些属性影响定位???
    其实我用form3.table.locate('字段名',nearname,[loPartialKey]);就查到了记录而且能够定位到查到的记录上。但是这个只能查到满足前半部分的记录
    没有sql那么灵活。所以我还是希望能够用
    'select * from fcz where name like ''%'+nearname+'%'''
    来查出记录再定位过去