Topic: Show specific record from database into textbox

Hello
Need a script to show record into texbox
Exemple
Table name : users
Column to search : name
Column to show record from : age

I want to enter the name into textbox1 and show the age into textbox2 depending on the name

Need script with SELECT sql query
Any help friends ?!

Re: Show specific record from database into textbox

Hi,
There are many ways to do this - which is best depends on what is most suited to your project.
In the attachment are 3 options.
Option1:  simply type in the name
Option2:  click on a name in the tablegrid
Option3:  select the name from the combobox.
As a general comment, it's not usually a good idea to hold someone's 'age' in a table - it is usually better to store their date of birth and then calculate their age when your program runs.
Derek.

Post's attachments

Attachment icon simokami.zip 443.77 kb, 65 downloads since 2024-01-10 

Re: Show specific record from database into textbox

Hi derek ,
Thanks for help
For the age it's just an example
I will test the project you attached

4 (edited by k245 2024-01-11 08:58:32)

Re: Show specific record from database into textbox

There is one caveat. If there are several users in the database with the same name, then you need to decide how to display the search result. Typically in this case the result is displayed as a comma separated list of values. The group_concat() SQL-function will help in implementing such functionality.

procedure option1 (Sender: TObject);
begin
  form1.edit2.text := sqlexecute('select GROUP_CONCAT(age,",") from example where name = "'+form1.edit1.text+'"');
end;

https://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=10193&download=0

Post's attachments

Attachment icon изображение_2024-01-11_115737343.png 20.55 kb, 15 downloads since 2024-01-11 

Визуальное программирование: блог и телеграм-канал.