ExecuteNonQuery()返回1没有任何更新或没有影响

时间:2013-10-26 01:15:52

标签: 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='" & 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

0 个答案:

没有答案