I have a winForms application with DataGridView, 3 tables and some queries.
Lets say I have Tables , A,B,C. In table AI have an auto increment primary Key and also in table B. Tables A and B are both strangers.
Table C is a Join Table that have 2 columns:
1) A primary Key
2) B primary Key
Now, in the form I have a button and it's just programmatically inserts values for table A and B. What I'm trying to do is to insert the primary keys of tables A and B to the right columns in table C. is it possible to do it programmatically?
if you using sql server you can run in your buttonclick code this:
declare @aid int, @bid int
insert A(col1) values(val1)
set @aid = scope_identity()
insert B(col1) values(val1)
set @bid = scope_identity()
insert C(aid, bid) values(@aid, @bid)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.