Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
help!!! i'm using c# and i want to add a data into my database tables using c#
since i have two tables having a relationship with tables
example:
table one column:did,dna,ddef,dsymp,dcompl;
table 2   column:syid,did,synam

then i want the user only inserts all column of table one and all column of table 2 except did which is foreign key and once inserted in table one then how can i re insert the foreign key using my code with out asking the user to isert repetedly??
" thanks for advice"
Posted

I think you best use a stored proedure like:
create proc p_Insert
(
	@dna <type>,
	@ddef <type>,
 	@dsymp <type>,
	@dcompl <type>,
	@synam <type>
)
as
declare @did int
declare @syid int
insert into t1 (dna,ddef,dsymp,dc) values(@dna,@ddef,@dsymp,@dc)
set @did = scope_identity()
insert into t2 (did, synam) values(@did @synam)
set @syid = scope_identity()

select did = @did, syid= @syid
The last select query will return the new id's to your program.
 
Share this answer
 
v2
After saving in the first table, execute an 'insert' command to add a new record in the second table with value of 'did'. Then use 'update' command, for the user values, on the particular record, by using value of 'did' in the 'where clause'.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900