[英]Delphi, Authentication from database
我計划在我的程序中包含身份驗證功能。
我需要有關在表記錄之間切換的信息。 我當前的程序只讀取第一條記錄中的用戶名和密碼 。
如何移動到后續表記錄?
數據集有一個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 ;
只需使用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
去最后一個。
這是真正基本的數據庫編程。 您應該搜索一個解釋它的教程並完成它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.