我如何在 VB.NET 的 ms 访问中使用 Autonumber 字段更新数据。我尝试使用此代码进行更新。但什么都没有改变。
Private Sub BTNUPDATE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNUPDATE.Click
Try
getConnect()
Dim strSQL As String
Dim iCount As Integer
strSQL = " UPDATE DEPARTMENT SET [DEPART]=@DEPART,[DEP_DSCRPTN]=@DEP_DSCRPTN WHERE [DEP_ID] = @DEP_ID"
Dim cmd As New OleDb.OleDbCommand(strSQL, Conn)
cmd.Parameters.AddWithValue("@DEP_ID", CInt(DEPID.Text))
cmd.Parameters.AddWithValue("@DEPART", CMBDEPT.Text)
cmd.Parameters.AddWithValue("@DEP_DSCRPTN", TXTDESC.Text)
Conn.Open()
iCount = cmd.ExecuteNonQuery()
Conn.Close()
If iCount > 0 Then
MessageBox.Show("Record Updated Successfully!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
If Windows.Forms.DialogResult.OK Then
BTNCLEAR.PerformClick()
End If
Else
MsgBox("No record was inserted")
End If
Catch ex As Exception
MsgBox("ERROR: " + ex.Message, MsgBoxStyle.Information, "Update")
Finally
BTNCLEAR.PerformClick()
End Try
End Sub
在数据库DEP_ID
中是自动编号。并且DEPID
是要检索的标签框DEP_ID
。实际上标签隐藏在表单中。我试试上面的代码。但是数据库没有任何变化。请检查我的代码并纠正我。