Okey pros i have a small question.assume that below sinario where i have a Two tables called Organizatioin and Organization_Members (One organization can have many members 1 to Meny)

Organizatioin

Organization_ID - PK
Organization_Name
Tel

Organization_Members

Member_ID - PK
Organization_ID - FK
First_Name
Last_Name
Tel

I recently developed a system for this type of senario where i get both details from the user in same page (easyer to use) in the same form i get organization details and in the same form i get who are the members in this organization (accoding to customer request).

My programming logic is first i got the Next increment value of Organizatioin table from the SQL database and stored it in a variable
afterward i did simple insert statement for organization table. for organization_memebers table i insert with user input data along with my next increment variable ( organization attached to member) it just worked fine
. i want to know is there any easy / genuine way to preform the same task in my future projects ? thank ou

We don't know how/what your future projects will/are grow...or how it needs to interact with these tables.

you can use select @scope_identity in sql...

It's safer to use the OUTPUT clause as @scope_identity will return the last identity generated in the current session & scope regardless of the table.

Although it's generally ok to use @scope_identity using the OUTPUT clause will always achieve the intended result regardless of parallelism. It's a bit clunky to write, but you can have better faith in the executing code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.