这是我从其他人开始继承的一个例子。他们对表进行了一些更改,现在当插入SHOP_INV时,会自动生成列SI_KEY。我需要将SI_KEY返回到表单中。不幸的是,我不知道该怎么做。我还不确定是否必须将SI_KEY列放在insert语句中,如果它是一个我从现在自动生成以来不能提供该值的列。我不认为我这样做,我没有在我的例子中包含它。否则它将在CATEGORY
之前。代码是有效的。
STSQL = "insert into SHOP_INV"
STSQL = STSQL & " ("
STSQL = STSQL & "CATEGORY,"
STSQL = STSQL & "MTI_PART_NO,"
STSQL = STSQL & "DESCRIPTION,"
STSQL = STSQL & "CONSUMABLE"
STSQL = STSQL & ") values ("
STSQL = STSQL & "1,"
STSQL = STSQL & "2,"
STSQL = STSQL & "3,"
STSQL = STSQL & "4"
STSQL = STSQL & ")"
MPCS_UPDATE_SQL(UCase(STSQL))
然后从ModModule
Public Sub MPCS_UPDATE_SQL(ByVal strSQL As String)
Dim cmdMPCS As OleDbCommand
Try
If OPEN_CONNECTIONS() = False Then
MessageBox.Show("Error connecting to database.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
Else
cmdMPCS = New OleDbCommand(strSQL, conMPCS)
cmdMPCS.ExecuteNonQuery()
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
Err.Clear()
Exit Sub
End Try
End Sub