0

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

这是我的代码:

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
4

0 回答 0