I'm having problems figuring out the code to update records from a web form to an access database. I have a button which Adds a new record to the database, which works. However, I'm having trouble trying to code the Update button.
Here is what i'm using to Add Records to my database. Any suggestions for Updating records?
Private Sub lnkSaveClaim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkSaveClaim.Click
'If user has filled every text box correctly...
If Page.IsValid Then
'Create a temporary dataset to contain the new record
Dim dsTemp As New DataSet
'Fill the temporary dataset
daNewClaim.Fill(dsTemp)
'Create a new row
Dim r As DataRow = dsTemp.Tables(0).NewRow()
'Add the category, reading its value from the text box
r("Account Name") = ddlInsured.SelectedItem()
r("Division") = ddlDivisions.SelectedItem
r("TrailorType") = ddlTrailorType.SelectedItem
r("INSCompany") = txtInsCo.Text
r("Policy_ID") = txtPolicyID.Text
r("Policy Number") = txtPolicyNumber.Text
r("Claim Number") = txtClaimNUmber.Text
r("Type of Loss") = ddlLossType.SelectedItem
r("Insurance Claim Number") = txtInsClaimNumber.Text
r("Claim Status") = ddlStatus.SelectedItem
r("Date Closed") = txtDateClosed.Text
r("Reopen") = txtReopened.Text
r("ReClosed") = txtReClosed.Text
r("Report Date") = txtReportDate.Text
r("Date of Loss") = txtDateofLoss.Text
r("Time of Loss") = txtTimeofLoss.Text
r("City of Loss") = txtCityofLoss.Text
r("State of Loss") = txtStofLoss.Text
r("Location Code") = ddlLocationType.SelectedItem
r("Tractor") = txtTractor.Text
r("Trailer1") = txtTrailor.Text
r("VIN") = txtVIN.Text
r("Unladen?") = ckbUnladen.Checked
r("TPA") = ckbTPA.Checked
r("Subrogation") = ckbSubro.Checked
r("Last Name") = txtLast.Text
r("First Name") = txtFirst.Text
r("MI") = txtMiddle.Text
r("License Number") = txtLicNum.Text
r("License State") = txtLicSt.Text
r("Driver Hire Date") = txtStartDAte.Text
'Add the new row into the dataset's row collection
dsTemp.Tables(0).Rows.Add(r)
'Update the database using the temporary dataset
daNewClaim.Update(dsTemp)
End If
Here is what i'm using to Add Records to my database. Any suggestions for Updating records?
Private Sub lnkSaveClaim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkSaveClaim.Click
'If user has filled every text box correctly...
If Page.IsValid Then
'Create a temporary dataset to contain the new record
Dim dsTemp As New DataSet
'Fill the temporary dataset
daNewClaim.Fill(dsTemp)
'Create a new row
Dim r As DataRow = dsTemp.Tables(0).NewRow()
'Add the category, reading its value from the text box
r("Account Name") = ddlInsured.SelectedItem()
r("Division") = ddlDivisions.SelectedItem
r("TrailorType") = ddlTrailorType.SelectedItem
r("INSCompany") = txtInsCo.Text
r("Policy_ID") = txtPolicyID.Text
r("Policy Number") = txtPolicyNumber.Text
r("Claim Number") = txtClaimNUmber.Text
r("Type of Loss") = ddlLossType.SelectedItem
r("Insurance Claim Number") = txtInsClaimNumber.Text
r("Claim Status") = ddlStatus.SelectedItem
r("Date Closed") = txtDateClosed.Text
r("Reopen") = txtReopened.Text
r("ReClosed") = txtReClosed.Text
r("Report Date") = txtReportDate.Text
r("Date of Loss") = txtDateofLoss.Text
r("Time of Loss") = txtTimeofLoss.Text
r("City of Loss") = txtCityofLoss.Text
r("State of Loss") = txtStofLoss.Text
r("Location Code") = ddlLocationType.SelectedItem
r("Tractor") = txtTractor.Text
r("Trailer1") = txtTrailor.Text
r("VIN") = txtVIN.Text
r("Unladen?") = ckbUnladen.Checked
r("TPA") = ckbTPA.Checked
r("Subrogation") = ckbSubro.Checked
r("Last Name") = txtLast.Text
r("First Name") = txtFirst.Text
r("MI") = txtMiddle.Text
r("License Number") = txtLicNum.Text
r("License State") = txtLicSt.Text
r("Driver Hire Date") = txtStartDAte.Text
'Add the new row into the dataset's row collection
dsTemp.Tables(0).Rows.Add(r)
'Update the database using the temporary dataset
daNewClaim.Update(dsTemp)
End If