我计划在我的程序中包含身份验证功能。
我需要有关在表记录之间切换的信息。我目前的计划只是从第一条记录中读取用户名和密码。
如何移至后续表记录?
答案 0 :(得分:1)
数据集有一个Next方法,这样你就可以遍历整个数据集。
qDS.Open ;
while not qDS.EOF do
begin
anyString := qDS.fieldbyname('usern').asString ; // will give you the username
qDS.Next ; // go to the next record in the dataset.
end ;
qDS.close ;
答案 1 :(得分:1)
只需使用TDataSet.Locate
即可。在以下所有内容中,我使用ds
来表示您的TDataSet
变量。
UserName := EditUserName.Text;
Password := EditPassword.Text;
if ds.Locate(UserName, ['UserNameField']) then
begin
if ds.FieldByName('Password').AsString = Password then
// Passwords match
else
// Passwords don't match
end
else
// User name not found
要从一个记录(行)移动到下一个记录(行),只需使用ds.Next;
,然后在使用ds.Prior;
之前移至该记录。要转到第一行,请使用ds.First
和ds.Last
转到最后一行。
这是真正基本的数据库编程。您应该搜索一个解释它的教程并完成它。