Update/edit vb access

Submitted by:Tim Kelly

Date added:28 November, 2013

Category:VB.NET

Edit database using vb + access

Tags: edit database , edit vb

Code Snippet:

    Private Sub EditRental()
Dim RentalDR As DataRow = frmRental.dsRental.RENTAL.Rows.Find(CInt(lblID.Text))
uProceed = True '-- not needed for basic edit/update

Try
'' Edit anything you want to edit
RentalDR.BeginEdit()
RentalDR("rDate") = Format(dtpDate.Value, My.Settings.DateFormat)
RentalDR("rDesc") = txtDesc.Text
RentalDR("rAmount") = CDbl(txtAmount.Text)
RentalDR("rStatus") = cmbStatus.Text
RentalDR.EndEdit()
Catch ex As Exception
iProceed = False ' Block procedures if exception happens.
MessageBox.Show("Please check your input. Make sure all input is correct.", "Invalid Input(s)", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try

If uProceed = True Then
Try
frmRental.daRental.Update(frmRental.dsRental)
MessageBox.Show("Database successfully updated.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

Me.Close()
Catch ex As Exception
MessageBox.Show("Somehow I cannot update the database. =(", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
 
 

Comments