0

I am planing to include authentication capabilities in my program.

I need information about switching between table records. My current program is only reading the username and password from the first record.

How do I move to subsequent table records?

5
  • That's great to hear! :-) What you're having trouble with ? Commented Jun 13, 2013 at 12:10
  • problem is in that how to make programm switch to next record if current records usern. and pasw. checking fails Commented Jun 13, 2013 at 12:11
  • You should look up the TDataSet.Locate method. It moves the record to matching criteria, and returns false if the record is not found Commented Jun 13, 2013 at 12:14
  • Hmm, i realy dont know what are u talking about. Im comparing authentications forms edit.text fields with DBedit.text fields... If you would say what code rows should be added, that would be great, ty! !! Commented Jun 13, 2013 at 12:23
  • If your database supports SQL it could be easier to execute a SQL SELECT COUNT(*) FROM USERTABLE WHERE <username>=:param1 and <password>=:param2 statement - instead of navigating through a dataset Commented Jun 16, 2013 at 20:01

2 Answers 2

1

Just use TDataSet.Locate. In all of the below, I'm using ds to represent your TDataSet variable.

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

To move from one record (row) to the next, simply use ds.Next;, and to move to the one before use ds.Prior;. To go to the first row, use ds.First, and ds.Last to go to the last one.

This is really basic database programming. You should probably search for a tutorial that explains it and work through it.

Sign up to request clarification or add additional context in comments.

Comments

1

Dataset has a Next method, that way you may traverse the whole dataset.

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 ;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.