我有2个表, TableA 和 TableB 。 IMAT_PRIORITY_ID
是TableA中的主键。
如何在插入TableA后在文本框中获取 IMAT_PRIORITY_ID 的值?
strSQL1 = "INSERT TableA (IMAT_PRIORITY_ID,JOB_NO,BATCH_NO) VALUES (SQ_PRIOTITY_ID.nextval," & JOB_NO.Text & "','" & BATCH_NO.Text & "')"
With adoCommand
.ActiveConnection = adoconn
.CommandType = adCmdText
.CommandText = strSQL1
.Prepared = True
.Execute , , adCmdText + adExecuteNoRecords
End With
strSQL1 = "INSERT TableB (ISBN_SERIAL_NO,IMAT_PRIORITY_ID,ISBN) VALUES (ISBN_SERIAL_NO.NEXTVAL,'" & IMAT_PRIORITY_ID.Text & "','" & ISBN.Text & "')"
With adoCommand
.ActiveConnection = adoconn
.CommandType = adCmdText
.CommandText = strSQL1
.Prepared = True
.Execute , , adCmdText + adExecuteNoRecords
End With
答案 0 :(得分:0)
要获取从insert语句生成的最后一个标识(PRIMARY KEY),您可以按如下方式查询它。
strSQL1 =“INSERT TableA(IMAT_PRIORITY_ID,JOB_NO,BATCH_NO)VALUES(SQ_PRIOTITY_ID,JOB_NO,BATCH_NO)VALUES(SQ_PRIOTITY_ID.nextval,”& JOB_NO.Text&“','”& BATCH_NO.Text&“ '); SELECT SCOPE_IDENTITY()“
您可以在here
上找到更多详情