简体   繁体   中英

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.

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 . In all of the below, I'm using ds to represent your TDataSet variable.

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; , and to move to the one before use ds.Prior; . To go to the first row, use ds.First , and ds.Last to go to the last one.

This is really basic database programming. You should probably search for a tutorial that explains it and work through it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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