一直试图找出为什么以下登录验证过程不起作用。我有一个简单的数据库表,其中包含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