简体   繁体   English

Delphi,来自数据库的身份验证

[英]Delphi, Authentication from database

I am planing to include authentication capabilities in my program. 我计划在我的程序中包含身份验证功能。

I need information about switching between table records. 我需要有关在表记录之间切换的信息。 My current program is only reading the username and password from the first record. 我当前的程序只读取第一条记录中的用户名密码

How do I move to subsequent table records? 如何移动到后续表记录?

Dataset has a Next method, that way you may traverse the whole dataset. 数据集有一个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 ;

Just use TDataSet.Locate . 只需使用TDataSet.Locate In all of the below, I'm using ds to represent your TDataSet variable. 在下面的所有内容中,我使用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

To move from one record (row) to the next, simply use ds.Next; 要从一个记录(行)移动到下一个记录(行),只需使用ds.Next; , and to move to the one before use ds.Prior; ,并在使用之前移动到一个ds.Prior; . To go to the first row, use ds.First , and ds.Last to go to the last one. 要转到第一行,用ds.Firstds.Last去最后一个。

This is really basic database programming. 这是真正基本的数据库编程。 You should probably search for a tutorial that explains it and work through it. 您应该搜索一个解释它的教程并完成它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM