請幫助我...我試圖從VB.net更新我的數據庫。它顯示錯誤。我的代碼如下....使用標識列更新數據庫時出現錯誤
Try
getConnect()
Dim strSQL As String
strSQL = " UPDATE DEPARTMENT SET [DEP_ID][email protected]_ID,[DEPART][email protected], [DEP_DSCRPTN][email protected]_DSCRPTN WHERE [DEP_ID] = @DEP_ID"
Dim cmd As New SqlCommand(strSQL, Conn)
cmd.Parameters.AddWithValue("@DEP_ID", CInt(Me.DEPID.Text))
cmd.Parameters.AddWithValue("@DEPART", SqlDbType.VarChar).Value = CMBDEPT.Text
cmd.Parameters.AddWithValue("@DEP_DSCRPTN", SqlDbType.VarChar).Value = TXTDESC.Text
Conn.Open()
cmd.ExecuteNonQuery()
MsgBox("Update Complete!", MsgBoxStyle.Information, "Update")
Catch ex As Exception
MsgBox("ERROR: " + ex.Message, MsgBoxStyle.Information, "Update")
Finally
Conn.Close()
BTNCLEAR.PerformClick()
End Try
和錯誤是:
ERROR: Cannot update identity column 'DEP_ID'
錯誤消息已清除,請移除Set DEP_ID = @DEP_ID部分。 – Steve