Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi ADOTable help.

Status
Not open for further replies.

Crytach

Programmer
Oct 21, 2020
1
ES
Hey People, so Im going to be blunt, I am a newbie programmer and have started building a school database. I have it all hooked up but my issue is the displaying of data. I know most of you are going to curse me for what I am about to show you but this was my friends request, as such no DBGrid for this project.

Capture1_udvap4.png


now as you can see, what he wants is the data to be inserted from the ADOTable into the data boxes so that they can be changed as needed.

this is the code currently

Code:
procedure TfSearch.BtnSearchClick(Sender: TObject);
begin
    DBComboBox1.AutoComplete:= True;
    ADOTable1.Open;
while not ADOTable1.Eof do
        begin
          if (ADOTable1['Student Name'] = DBComboBox1.Text)
          then
          begin
            EdtName.Text := ADOTable1['Student Name'];
            EdtSurname.Text:= ADOTable1['Surnames'];
            EdtDate.Date :=  ADOTable1['Birthdate'] ;
            EdtMobile.Text := ADOTable1['Mobile Number'];
            EdtFixed.Text := ADOTable1['Fixed Number'];
            EdtEmail.Text := ADOTable1['Email Address'];
            EdtLevel.Text := ADOTable1['Student Level'];
            EdtMomName.Text := ADOTable1['Mothers Name'];
            EdtMomNum.Text := ADOTable1['Mothers Number'];
            EdtDadName.Text := ADOTable1['Fathers Name'];
            EdtDadNum.Text := ADOTable1['Fathers Number'];
            EdtEmergency.Text := ADOTable1['Emergency Contact'];
          end
          else
          ShowMessage('Student Not Found!');
          Exit;
        end;
end;

Now my issue is that the search function works once. It displays all the data, however when you search a second record it only changes the Student Name.
Now no matter how much I look I have no Idea how to search for information by row. Is there a way to make it search by row and not by individual field?

I realise my code is probably Horrific, And I will get better in time. if you have any recommendations I will take what I can get.
 
First, you're not iterating through the ADOTable. While you have an "not ADOTable1.EOF", you never move to the next record. You don't see that behavior because the Exit is outside your IF..THEN..ELSE statement. So, in your code, you check for "not EOF" then exit the procedure after the first record. Third, your comparison may not always work. It doesn't take into account case ("NAME" vs "name") and it doesn't take into account padded spaces ("Name " vs "Name"). Fourth, you probably should look at Locate rather than using the DBComboLookup and a text comparison.
Something like this might work. I didn't test it.
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
    if (ADOTable1.Locate('Student Name',EdtNameSearch.Text, [loCaseInsensitive, loPartialKey]))
    then
    begin
      EdtName.Text := ADOTable1['Student Name'];
      EdtSurname.Text:= ADOTable1['Surnames'];
      EdtDate.Date :=  ADOTable1['Birthdate'] ;
      EdtMobile.Text := ADOTable1['Mobile Number'];
      EdtFixed.Text := ADOTable1['Fixed Number'];
      EdtEmail.Text := ADOTable1['Email Address'];
      EdtLevel.Text := ADOTable1['Student Level'];
      EdtMomName.Text := ADOTable1['Mothers Name'];
      EdtMomNum.Text := ADOTable1['Mothers Number'];
      EdtDadName.Text := ADOTable1['Fathers Name'];
      EdtDadNum.Text := ADOTable1['Fathers Number'];
      EdtEmergency.Text := ADOTable1['Emergency Contact'];
    end
    else
    begin
      // Might want to clear or disable the Text fields here since nothing was found.
      ShowMessage('Student Not Found!');
      Exit;
    end;
end;


Mirtheil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top