Vb.net ExecuteNonQuery()返回1而不进行任何更新或不影响

Vb.net ExecuteNonQuery()返回1而不进行任何更新或不影响,vb.net,ms-access,Vb.net,Ms Access,我正在检查数据库表中有多少行受到影响 这是我的密码: Try Dim RowsAffected As Integer con = New OleDbConnection(cs) con.Open() Dim cb As String = "update Hostel set HostelName='" & txtHostelName.Text & "', address='" & txtAddress.Text & "',Phone

我正在检查数据库表中有多少行受到影响

这是我的密码:

Try
    Dim RowsAffected As Integer
    con = New OleDbConnection(cs)
    con.Open()
    Dim cb As String = "update Hostel set HostelName='" & txtHostelName.Text & "', address='" & txtAddress.Text & "',Phone='" & txtPhoneNo.Text & "',ManagedBy='" & txtManagedBy.Text & "',contactno='" & txtContactNo.Text & "' where hostelname= '" & TextBox1.Text & "'"
    cmd = New OleDbCommand(cb)
    cmd.Connection = con
    RowsAffected = cmd.ExecuteNonQuery()
    If RowsAffected > 0 Then
        MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
        MsgBox("The no.of rows affected by update query are " & RowsAffected.ToString)
    Else
        MessageBox.Show("No changes were made", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)

    btnUpdate_record.Enabled = False
    con.Close()
Catch ex As Exception
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

为什么你认为没有更新?您确定传递了正确的密钥,并且在更新前后检查了数据吗?是的,如果没有任何更新,则返回1警告您的代码容易受到sql注入攻击。在没有数据更改的情况下,可能会发生更新,例如,如果您传递的数据与行中的数据相同,但这仍然算作更新。如果表上有一个触发器,并且该触发器更新了其他行,那么它仍然会得到一个正值。