如何让我的搜索框从一个关键字跳转到另一个没有它检查数据库的每一行? [英] how can i make my search box jump from one keyword to another without it check every row of the database?

查看:204
本文介绍了如何让我的搜索框从一个关键字跳转到另一个没有它检查数据库的每一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码适用于我的应用程序的搜索框,不幸的是当它的搜索或过滤器,它检查数据库上的每一行,然后当搜索到的词,它将显示在tlabels,

I got this code working for my app's search box, unfortunately when it search or filters, it checks every row on the database and then when the searched word is found, it will display it on the tlabels,

procedure Tspcb.dccolbtnClick(Sender: TObject);
begin
  zdctable.First;
  while not zdctable.EOF do
  begin
     if (zdctable.FieldByName('Collector').AsString = dcedit.Text)
     then begin
        cn.Caption := zdctable.FieldByName('Client_Name').AsString;
        col.Caption := zdctable.FieldByName('Collector').AsString;
        pay.Caption := zdctable.FieldByName('Daily_Payment').AsString;
        date.Caption := zdctable.FieldByName('Date').AsString;
        ddate.Caption := zdctable.FieldByName('Due_Date').AsString;
        id.Caption := zdctable.FieldByName('ID').AsString;
        la.Caption := zdctable.FieldByName('Loan').AsString;
        tc.Caption := zdctable.FieldByName('Total_Collectibles').AsString;
     end;

     ShowMessage('click ok for next profile');
     zdctable.Next;
  end;
end;

我想做的是检查有搜索字词的行,而不是在数据库中搜索每一行。

what i want to do is for it to check rows that has the searched word on it, and not searching every row in the database.

我需要帮助分析这段代码,只是一个初学者谁正在学习如何使用delphi 7和编程。

i need help on analyzing this code, im just a beginner who is learning how to use delphi 7 and to program.

谢谢

推荐答案

问题基本上是用

if (zdctable.FieldByName('Collector').AsString = dcedit.Text)

这里你正在寻找平等,所以你永远不能匹配部分字符串。我建议您更改您的查询(即zdctable),使其看起来像这样

Here you're looking for equality, so you're never going to be able to match partial strings. I suggest that you change your query (ie zdctable) so that it looks something like this

select * from zdctable
where collector like :p1

您的程序将是

zdctable.params[0].asstring:= '%' + dcedit.text + '%';
zdctable.open;

如果您的表通过数据源链接到网格,那么将显示所有匹配的记录;将不需要提取每个字段并在不同的标签中显示它。如果要使用导航器一次显示一个记录,则将标签转换为链接到数据集的dbtext组件;如果这些组件设置正确,则数据集中的每个字段将显示在不同的dbText组件中。

If your table is linked to a grid via a datasource, then all the matching records will be displayed; there will be no need to extract each field and show it in a different label. If you want to show one record at a time with a navigator, then turn your labels into dbtext components which are linked to the dataset; if these components are set up correctly then each field in your dataset will be displayed in a different dbText component.

另一种可能性是使用'locate'方法。如果我将你的语句转换为使用'locate',那么你写了相当于

Another possibility is using the 'locate' method. If I convert your statement to use 'locate', then you have written the equivalent of

zdctable.locate ('collector', dcedit.text, [])

为了定位部分匹配, p>

In order to locate partial matches, you would need to write

zdctable.locate ('collector', dcedit.text, [loPartialKey])

这篇关于如何让我的搜索框从一个关键字跳转到另一个没有它检查数据库的每一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆