Topic: Showing details

I used same script for showing customers details on form1 customers and invoices tab.
Script works for customers tab but not on invoices tab.
Difference is that inv tgGrid on Invoices tab displaying data from InvoiceHeader table therefore invoice details displayed, however customer details are not .
I have linked InvoiceHeader table to Customers table but couldn't get it working.


Please see the attached sample project:

Post's attachments

Attachment icon Showing details.zip 62.47 kb, 346 downloads since 2017-01-27 

Adam
God... please help me become the person my dog thinks I am.

Re: Showing details

Hello Adam,
Please find attached your project with the problem (as I understand it) fixed.
In your original script, you were trying to retrieve the customer details using the key of the invoiceheader table from the invoiceheader grid. 
What you need to do is get the foreign key (id_customers) off the invoiceheader table from the invoiceheader grid AND THEN retrieve the customer details using the foreign key value.
In effect, what you are doing is a 'nested select' (I'm sure there's a technical term for it!!).
Have a look at the sections that I've changed and I think you'll see why it wasn't working.
I may have missed some other bits that you might have to fix but the principle (and the code) is exactly the same.
Regards,
Derek.

Post's attachments

Attachment icon Showing details fixed.zip 397.08 kb, 328 downloads since 2017-01-27 

Re: Showing details

Hi Derek,


Thank you sooooooooo much...................


I got the dates was left out among image fields but couldn't convert the image script below to 'nested select' script:

Form1.dbiSearchDetCustImage.LoadFromDatabase('Customers', 'image', Form1.tgSearch_Invoices.dbItemID);
Adam
God... please help me become the person my dog thinks I am.

Re: Showing details

AD1408 wrote:

Hi Derek,
..........

I got the dates was left out among image fields but couldn't convert the image script below to 'nested select' script:

Form1.dbiSearchDetCustImage.LoadFromDatabase('Customers', 'image', Form1.tgSearch_Invoices.dbItemID);

Derek, I guess the above for Dmitry

Adam
God... please help me become the person my dog thinks I am.

Re: Showing details

Hi Adam,
I did it as below (probably not the cleverest code on the block!):
Declare a variable (vkey: integer) and then change your script to the following:
Form1.dbiSearchDetCustImage.Clear;
vkey := sqlexecute('select id_customers from invoiceheader where id =' +inttostr(form1.tgSearch_Invoices.dbitemid));
Form1.dbiSearchDetCustImage.LoadFromDatabase('Customers', 'image', vkey);
The above code is in the attachment but you might just want to cut and paste the above if you've made other changes in the meantime.
Derek.

Post's attachments

Attachment icon Showing details fixed.zip 397.32 kb, 370 downloads since 2017-01-28 

Re: Showing details

Derek,


Thank you VERY much for quick reply...............................


I tried many variations without var and I couldn't get it working.
Your code with var works fine.

Adam
God... please help me become the person my dog thinks I am.