Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Delphi
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 12-Jul-12 9:31am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 :
 
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 :
 
  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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100