Database integration: Foreign Keys

Database integration: Foreign Keys

Hi all!

Following this example that helped me a lot (, I still have a question:
If table STTAB_DADOS has a primary key “ID”, Integer and Autonumber, how can we incorporate this with another additional table (STTAB_TABLE2) having a Foreign Key to STTAB_DADOS’s “ID” column?

I mean something like this:
rec.ssSTTAB_TABLE2.ssNEW_ID_SSTTAB_DADOS = rec.ssSTTAB_DADOS.ssID; ??? (doesn't work)

Thanks in advance!
The error is being logged in Service Center and is specified as a foreign key constraint error.
The problem is the value is always 0…
I cannot assign that in Service Studio, because I have data that I need to manipulate directly from my C# code.

Basically I have an hashtable that contains certain objects. I was trying to fill those objects to a Record List (the code I presented in C#) and then returning it to Service Studio for entity manipulation.

Thanks again.
Can no one help me with this? Still stuck...

Maybe there’s an easier way to accomplish this, but I’m not sure how....

Maybe I'm not understanding your problem properly, but I think all you would need to do is to read the table with the PK first and after that read the table that has th FK to that first table.

What's the error your getting?

Tiago Simões
Thanks for your help!

I have two tables:
- The “first table” has an ID, Integer and Autonumber.
- The “second table” has a Foreign Key to the “first table”'s ID column.

Basically, the problem is, filling data to those tables, how can I know the “first table”'s ID, since it is Autonumber?

I mean something like this:

This doesn’t work because its value is always 0 (rec.FIRST_TABLE.ssID), throwing a foreign key constraint error.

Code excerpt:

foreach (string IP in ((Hashtable)ssHashtable).Keys)
RCNetworkDeviceRecord ndr = new RCNetworkDeviceRecord(null);
//Filling data...
ndr.ssENNetworkDevice.ssScanDate = scanDate;

foreach (string[] cEnt in cIP.Gateways())
RCGatewayRecord gwr = new RCGatewayRecord(null);
//Filling data...
gwr.ssENGateway.ssScanDate = scanDate;

gwr.ssENGateway.ssID_NetworkDevice = ndr.ssENNetworkDevice.ssID_NetworkDevice;

Maybe there's another way to accomplish this.... But I'm not figuring it out...
The example you are based on is to read data from DB2 and what you are trying to accomplish is to save data to the database, if I'm understanding correctly. I'm not really sure how to do that inside an extension, maybe someone else can help. I know that the Append action is only to append to the in-memory recordlist, and will not to save it to the database.

But you could also just use the extension to retrieve the data in a structure (or 2) and then use service studio logic to save to the database. I'm not seeing the full picture, but architecturally maybe this would also be the best option.
Tiago Simões
>>But you could also just use the extension to retrieve the data in a structure (or 2) and then use service studio logic to save to the database.

Commonly speaking, I want to fill my database Entities (using Service Studio) with every object from an Hashtable (in C#).

Is this possible using Structures? Your idea is to pass a RecordList of Structures from my C# code to Service Studio using Integration Studio, and then saving to the database?
Is there any example? And isn't that considered analogous to what I was trying to do?

Thanks again for your help! :)
Still wondering... If anyone can help me, I'll appreciate it.