我有这个代码来更新数据库,但是当我使用正确的数据运行它时,它执行没有错误但数据库不是更新
Dim conn As New SqlClient.SqlConnection(My.Resources.conn_str)
Dim SQL As String = "Update vehicle SET make=@make,reg_no=@reg_no,model=@model,year=@year,type=@type,last_service=@last_service Where (id = @id)"
conn.Open()
Try
Dim cmd As New SqlClient.SqlCommand(SQL, conn)
Try
cmd.Parameters.AddWithValue("@make", strMake)
cmd.Parameters.AddWithValue("@reg_no", strRegnNum)
cmd.Parameters.AddWithValue("@model", strModel)
cmd.Parameters.AddWithValue("@year", intYear)
cmd.Parameters.AddWithValue("@type", strType)
cmd.Parameters.AddWithValue("@last_service", LastService)
cmd.Parameters.AddWithValue("@id", ID.ToString)
cmd.ExecuteNonQuery()
cmd.Dispose()
Catch ex As Exception
Return ex.Message
End Try
Catch ex As Exception
Return ex.Message
Finally
conn.Dispose()
End Try
任何人都可以帮助我解决它无法正常工作的原因,因为我没有收到错误消息吗?
感谢
EDIT 我用
替换了 cmd.ExecuteNonQuery()Dim intAffected As Integer = cmd.ExecuteNonQuery()
Debug.Print(intaffected)
我在输出窗口中得到1
答案 0 :(得分:2)
一些想法: