问一个关于DataSet数据定位的问题,请高手们不吝赐教

汤臣一丁 2005-09-23 04:03:30
请问如何在DataSet里通过已经知道一个字段的值,查询出另一个字段的值;就犹如SQL语句里的这个语法:Select fieldA from Table1 where fieldB = 'C';

DS 不能用FILTER筛选,因为还有用;

请高手们赐教一二,不胜感激;
...全文
93 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
binbin 2005-09-24
  • 打赏
  • 举报
回复
数据集的Locate方法
kwokwinglau 2005-09-24
  • 打赏
  • 举报
回复
Implements a virtual method to retrieve field values from a record that matches specified search values.

virtual System::Variant __fastcall Lookup(const AnsiString KeyFields, const Variant &KeyValues, const AnsiString ResultFields);

Description

This function

Checks whether the dataset is unidirectional, and if so, raises an EDatabaseError exception.
Returns a Variant with the value false, indicating that a matching record was not found.

Descendant classes that are not unidirectional override this method so that it locates the record where the fields identified by the comma-delimited string KeyFields have the values specified by the Variant or Variant array KeyValues. In classes that implement Lookup, it returns a Variant or Variant array that contains the value or values of the fields specified by the comma-delimited string ResultFields on the specified record.

Select fieldA from Table1 where fieldB = 'C'; ---> Table1->Lookup("fieldB","C","fieldA");
xibingwuqing 2005-09-23
  • 打赏
  • 举报
回复
WantedValue = Ds->DataSet->FieldByName("B");
好像应该是WantedValue = Ds->DataSet->FieldByName("B")->AsString;

xibingwuqing 2005-09-23
  • 打赏
  • 举报
回复
bool LocateSuccess;
TLocateOptions Opts;
String WantedValue, KeyValue;

Opts.Clear();
Opts << loCaseInsensitive;
LocateSuccess = Ds->DataSet->Locate("A", KeyValue, Opts);
if(LocateSuccess)
WantedValue = Ds->DataSet->FieldByName("B");
随便写的,可能有错,试试吧

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧