Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to create a function that will verify users before allowing them to login. The userID, Password and Name are stored in a data-base (MS Access). The function takes the ID, Password and Name that the user has entered and compares it to that found in the database. However when trying to find the users information through a SQL query the following error occurs: 'Parameter Brent has no default value' Brent is the user name entered by the user by means of selecting it from a drop-down menu (as to avoid spelling errors etc. the Delphi code follows:


function check (Name, ID, Password : string) : string;
var
  myLoop : integer;
  myField : string;
begin
  form1.ADOQuery1.Active := false;
  form1.ADOQuery1.SQL.Text := 'SELECT [employee ID], Password, Name FROM Employees WHERE Name = ' + name;
  form1.ADOQuery1.Active := true;

  {for myLoop := 1 to 3 do
  begin
  myField := form1.DataSource1.DataSet.Fields[myLoop].AsString;
  showmessage(myField);
  unit1.arrEmployee[myLoop] := myField;
  end;

  if (arrEmployee[1] = ID) AND (arrEmployee[2] = Password) AND (arrEmployee[3] = Name) then
  showmessage('all your information is correct') else
  showmessage('your information is not all correct');  }  
Posted

1 solution

The error occurred maybe because you have record(s)that the Name field of theme are Null , add and null check to end of your query :

SQL
SELECT [employee ID], Password, Name FROM Employees WHERE Name = ' + name + ' AND Name IS Not Null';


Why you check the login this way ? you can easily do all login checks usign T-SQL query like :

Delphi
form1.ADOQuery1.Active := False;
form1.ADOQuery1.SQL.Text := 'SELECT [employee ID], Password, Name FROM Employees                                                  WHERE Name = ' + name + ' AND Password = ' + Password + ' AND[employee ID] =' + ID;
form1.ADOQuery1.Active := True;

if (form1.ADOQuery1.RecordCount > 0) then
  // Login
else
  // Login failed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900