I built a program that basically lets you navigate,edit,add,delete records in an access database. When i changed the connection over to an sql table "ish" hit the fan. the adding function and editing function turned into mush. i fixed the add function, but the edit is hairy. when i save it will keep the new value in the text box, but come to reopening the program the old value came back. i guess osme code is in order
VB Code:
  1. 'edit button
  2. Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
  3.         If btnAdd.Text = "&Cancel" Then
  4.             LockText()
  5.             btnEdit.Enabled = True
  6.             btnDelete.Enabled = True
  7.             btnAdd.Text = "&Add"
  8.             btnSave.Enabled = False
  9.             RejectChanges()
  10.             blnEdit = False
  11.         Else
  12.             unlockText()
  13.             NoNavigation()
  14.             btnSave.Enabled = True
  15.             btnAdd.Text = "&Cancel"
  16.             btnEdit.Enabled = False
  17.             btnDelete.Enabled = False
  18.             blnEdit = True
  19.             displayrecordposition()
  20.         End If
  21. end sub
  22. 'save button (don't mind what I have for edit already)
  23.  Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  24.         If blnAdd = True Then
  25.             Try
  26.                 Dim newrow As DataRow = DsSQL1.Dem.NewRow
  27.                 newrow("first") = txtFirst.Text
  28.                 newrow("last") = txtLast.Text
  29.                 newrow("ssn") = txtSSN.Text
  30.                 newrow("dob") = txtBday.Text
  31.                 DsSQL1.Dem.Rows.Add(newrow)
  32.             Catch exc As Exception
  33.                 MessageBox.Show("Unable to add record." & _
  34.                 ControlChars.NewLine & exc.Message, "dem")
  35.             End Try
  36.             blnAdd = False
  37.             lblRecordNumber.Text = "Record added"
  38.         End If
  39.         If blnEdit = True Then
  40. 'i know i need to fix this but to what?
  41.             Dim editrow As DataRow = DsSQL1.Dem.NewRow
  42.             editrow("first") = txtFirst.Text
  43.             editrow("last") = txtLast.Text
  44.             editrow("ssn") = txtSSN.Text
  45.             editrow("dob") = txtBday.Text
  46.             DsSQL1.Dem.Rows.Add(editrow)
  47.  
  48.         End If
  49.  
  50.         LockText()
  51.         GoNavigation()
  52.         btnSave.Enabled = False
  53.         btnAdd.Text = "&Add"
  54.         blnIsDirty = True
  55.         btnEdit.Enabled = True
  56.         btnDelete.Enabled = True
  57.  
  58.  
  59.     End Sub