一直試圖找出爲什麼以下登錄驗證過程不起作用。我有一個簡單的數據庫表,其中包含pupilID和密碼(在tblPupil中)。編譯時似乎連接正常,即程序Connection,但是當我運行程序Login時,程序似乎崩潰。事實上,我沒有收到任何錯誤消息,這可能會進一步說明我的問題!這可能是數據庫驅動程序問題嗎? (使用了Delphi7,與DevartSQLiteDirect司機SQLite數據庫)德爾福SQlite登錄程序崩潰
Procedure TForm1.Connection;
begin
SQLConnection1.Params.Add('Database=C:\SQLite\PupilDatabase');
try
// Establish the connection.
SQLConnection1.Connected := true;
label4.Caption := 'OK!';
except
on E: EDatabaseError do
ShowMessage('Exception raised with message' + E.Message);
end;
end;
Procedure TForm1.UserLogin;
var QueryPass : string;
Lcount : String;
cont : boolean;
begin
cont := false;
if InputID.Text = '' then
ShowMessage('Invalid Pupil ID')
else begin
cont := True;
While cont = True do
begin
// A random query
QueryPass := 'SELECT password FROM TblPupil Where pupilID = +InputID.Text+';';
try
// Assign the query to the object SQLQuery1.
SQLQuery1.SQL.Text := QueryPass;
SQLQuery1.open;
except
on E: Exception do
ShowMessage('Exception raised with message: ' + E.Message);
end;
SQLQuery1.First;
Lcount := SQLQuery1.FieldValues['password'];
if Lcount = InputPass.text then
begin
Form1.Hide;
Form16.show;
end
else
begin
ShowMessage('Wrong');
cont := false;
end;
Form1.Hide;
Form16.show;
end;
end;
end;
調試器告訴你什麼當你通過'UserLogin'代碼? – 2015-01-31 18:00:06
只有一個錯字?您的查詢是無效的。 'QueryPass:='SELECT password FROM TblPupil Where pupilID = + InputID.Text +';'這意味着'pupilID'必須等於一個帶有加號'+'和文本'InputID.Text'的字符串。我很確定這不是你想要的。正確的查詢應該如下所示:'QueryPass:='SELECT password FROM TblPupil Where pupilID ='''+ InputID.Text +''';' ;'或者如果字段pupilID是一個整數,那麼:'QueryPass:='SELECT password FROM TblPupil Where pupilID ='+ InputID.Text +';' ;' – 2015-01-31 21:38:27