[英]how to insert data into primary key and foreign key
I have three tables: 我有三个表:
ptID
firstName
lastName
address
impID
ptID
productID
productSerialNo
productID
productName
I am inserting data in PATIENT DETAILS
and IMPLANT DETAILS
table on the same page from single button click . 我只需单击一次,即可在同一页面上的“
PATIENT DETAILS
和“ IMPLANT DETAILS
表中插入数据。
I have a foreign key on the table IMPLANT DETAILS (productID)
which I populate through the value on the dropdown list. 我在表
IMPLANT DETAILS (productID)
上有一个外键,该键通过下拉列表中的值填充。
What my problem is how will I populate foreign key (ptID)
in IMPLANT DETAILS
table? 我的问题是如何在
foreign key (ptID)
IMPLANT DETAILS
表中填充foreign key (ptID)
? When ptID (PATIENT DETAIL)
will also be generated from the same button click at almost of the same time. 当几乎从同一时间单击同一按钮也将生成
ptID (PATIENT DETAIL)
时。 How would I do this in C#? 我将如何在C#中执行此操作?
I suggest you to use entity framework for this. 我建议您为此使用实体框架。 Please look this post Inserting Objects
请看这篇文章插入对象
You need to fire two sql queries to do this. 您需要触发两个sql查询才能执行此操作。
INSERT INTO PATIENT_DETAILS (firstName,lastName,address) VALUES(NULL,'text');
INSERT INTO IMPLANT_DETAILS(ptID,productID,productSerialNo) VALUES(LAST_INSERT_ID(),1,'text');
COMMIT;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.