我正在检查数据库表中受影响的行数。
这是我的代码:
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