Topic: Saving multiple values in one database field

Hello all MVD users, it's been a long time ! A lot of changes in my life for the past few months have kept me away from keyboard and coding :-)
Hope you all go well !

I'm sure my question as already been posted, but I couldn't find any reference to it...

I would like to assign keywords to a product I store in a database.
The simple solution would be to create for example 5 keywords fields in the product database, assigning them in order.
But what if I want more ?

My question is : instead of creating a fixed number of field for keywords, how would you concatenate x keywords in just one field ? And of course, how would you read them from database and display them in a form ?

Happy to be back with you all.

Cheers

Math

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Saving multiple values in one database field

Hello,


Maybe you fit one database field and component Memo (on each line to store one keyword) ?

Dmitry.

Re: Saving multiple values in one database field

Hello Dmitry,

Thank you for your fast answer as usual !
On second thought, saving multiple values in one single field is a bad idea. I'll try something else and keep you posted (I plan on a pairing table with only id in it).

But I still have another related question :

I'm trying to save records as I go from form to form (because I need the id of the newly created product for pairing it with keywords).

So the product is created and saved in FormA (no problem here), and when FormA is closed, FormB is opened.
In order to assign keywords to this product, I need to lookup it's id in the table "products".

Her'es my code :

Var
prod_id : String;

procedure new_product_Button1_OnClick (Sender: string; var Cancel: boolean);
begin

    new_product.hide;
    new_product_keywords.Show;
end;


procedure new_product_keywords_OnShow (Sender: string; Action: string);


begin
    prod_id := IntToStr(Last_Insert_id('products'));
    new_product_keywords.Label_prod_id.Caption := prod_id;
    new_product_keywords.Edit_prod_id.Text := prod_id;
end;



begin

end.

I have no error message, but the result (displayed in an Edit Field and in a label) is always 0.
What do you think am I doing wrong ?


Cheers

Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Saving multiple values in one database field

mathmathou
You can get ID of record from button with action "Save Record"

Form1.ButtonSave.dbGeneralTableId

or

new_product_keywords.Label_prod_id.Caption := IntToStr(new_product.ButtonSave.dbGeneralTableId);
Dmitry.

5 (edited by mathmathou 2015-11-05 01:34:16)

Re: Saving multiple values in one database field

Thank you Dmitry for your answer.

I found a way around that problem, but I might come back to it later smile smile smile smile

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor