delphi5里的adotable控件问题(100分)

  • 主题发起人 主题发起人 DDcai
  • 开始时间 开始时间
D

DDcai

Unregistered / Unconfirmed
GUEST, unregistred user!
adotable有个seek函数,但是帮助文档里好象没介绍,我用这段代码,提示说不提供此方法
if adotable1.Seek(acnt) then
begin
if pswd=adotable1.Fields[2].AsString then
begin result:=1;
//connect succeed
end
else begin result:=2;end;
end
else begin result:=3 end;
请问seek的具体用法是什么?或者adotable有什么别的查询命令?
 
Searches for a record using the current index
这是它的原文。
是不是你没有在这个字段上建索引?
如果你是用来验证密码,可以用SQL语句来验证:
SELECT * FROM YOURTABLE WHERE NAME = :PNAME AND PASSWORD = :PPASSWORD
就可以的呀!
而且ADOQUERY比ADOTABLE好用多了!!
 
TCustomADODataSet.Seek

Searches for a record using the current index.

TSeekOption = (soFirstEQ, soLastEQ, soAfterEQ, soAfter, soBeforeEQ, soBefore);
function Seek(const KeyValues: Variant; SeekOption: TSeekOption = soFirstEQ): Boolean;

Description

Call Seek to find a record with a specified value (or values) in the field (or fields) on which the current index is based. An index must be active to use Seek. The field used for the search is that of the currently active index. Seek moved the record pointer of the dataset based on the success of the search. If the search finds a record, the record pointer is moved to that record. If Seek does not find a record matching the value in KeyValues using the comparison method specified in SeekOption, the record pointer is positioned to the end of the dataset. Seek returns a boolean value reflecting the success of the search: True if a record was found or False if no record was found.

SuccessVar := ADODataSet1.Seek('Jones', soFirstEQ);

If the current index is based on more than one field, search values supplied in the Seek method must be for all fields sequentially from left to right in the index expression. That is, if the index is based on three fields, the search can be on the first field, the first and second fields, or on the first and second and third fields. It cannot be based only on the third field or on a combination of the first and third fields. To search based on multiple fields, pass a variant array to the Seek method.

KeyValues is the value to search for or multiple values if the index is based on multiple fields.

ADODataSet1.Seek(VarArrayOf([90030, 90020]), soFirstEQ);

SeekOption specifies the type of comparison made in determining whether the search was successful. SeekOption can be one of the six constants:

Seek Option Meaning

soFirstEQ Record pointer positioned at the first matching record, if one is found, or at the end of the dataset if one is not found.
soLastEQ Record pointer positioned at the last matching record, if one is found, or at the end of the dataset if one is not found.
soAfterEQ Record pointer positioned at matching record, if found, or just after where that matching record would have been found.
soAfter Record pointer positioned just after where a matching record would have been found.

soBeforeEQ Record pointer positioned at matching record, if found, or just before where that matching record would have been found.
soBefore Record pointer positioned just before where a matching record would have been found.
 
应该是搜索相关记录,有点像Locate,但不用指定搜索的列,会在所有列中寻找匹配的记录,
这样说来,就可以用它来做全文检索了!^_^
 
帮助中有介绍的,我用的是delphi6
Searches for a record using the current index.

TSeekOption = (soFirstEQ, soLastEQ, soAfterEQ, soAfter, soBeforeEQ, soBefore);
function Seek(const KeyValues: Variant; SeekOption: TSeekOption = soFirstEQ): Boolean;

Description

Call Seek to find a record with a specified value (or values) in the field (or fields) on which the current index is based. An index must be active to use Seek. The field used for the search is that of the currently active index. Seek moved the record pointer of the dataset based on the success of the search. If the search finds a record, the record pointer is moved to that record. If Seek does not find a record matching the value in KeyValues using the comparison method specified in SeekOption, the record pointer is positioned to the end of the dataset. Seek returns a boolean value reflecting the success of the search: True if a record was found or False if no record was found.

SuccessVar := ADODataSet1.Seek('Jones', soFirstEQ);

If the current index is based on more than one field, search values supplied in the Seek method must be for all fields sequentially from left to right in the index expression. That is, if the index is based on three fields, the search can be on the first field, the first and second fields, or on the first and second and third fields. It cannot be based only on the third field or on a combination of the first and third fields. To search based on multiple fields, pass a variant array to the Seek method.

KeyValues is the value to search for or multiple values if the index is based on multiple fields.

ADODataSet1.Seek(VarArrayOf([90030, 90020]), soFirstEQ);

SeekOption specifies the type of comparison made in determining whether the search was successful. SeekOption can be one of the six constants:

Seek Option Meaning

soFirstEQ Record pointer positioned at the first matching record, if one is found, or at the end of the dataset if one is not found.
soLastEQ Record pointer positioned at the last matching record, if one is found, or at the end of the dataset if one is not found.
soAfterEQ Record pointer positioned at matching record, if found, or just after where that matching record would have been found.
soAfter Record pointer positioned just after where a matching record would have been found.

soBeforeEQ Record pointer positioned at matching record, if found, or just before where that matching record would have been found.
soBefore Record pointer positioned just before where a matching record would have been found.

Using the Seek method depends on the settings of a few properties. IndexName must be set to activate the index to use, CommandType must be cmdTableDirect (for TADODataSet, set TableDirect to True for a TADOTable), CursorLocation must be clUseServer, and CursorType must be ctKeySet.

Note: The VCL Seek method is a direct implementation of the Seek method for the ADO Recordset object. At the time of this writing, this method is only supported for use with Microsoft Access2000 and the Jet 4 provider.
 
SQL语句吧,比较好些
 
是的,我现在换成adoquery了,但是seek为什么不能用我还是不明白,我已经把id字段设成索引了,
还有就是那个seek(key,firsteq...
~~~~~~~~~这个参数我不加没事,一加反而报错。
 

Similar threads

S
回复
0
查看
911
SUNSTONE的Delphi笔记
S
S
回复
0
查看
888
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部