here is my modification button code :
Private Sub btnmodify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodify.Click
btnsave.Visible = True
cmdRequery.Visible = True
txtfirstname.Enabled = True
txtlastname.Enabled = True
ComboBox1.Enabled = True
txttitlec.Enabled = True
txtadress.Enabled = True
txtpostalcode.Enabled = True
txtnotes.Enabled = True
txthomephone.Enabled = True
txtextension.Enabled = True
cmbcountry.Enabled = True
Cmbcity.Enabled = True
cmbregion.Enabled = True
birthdate.Enabled = True
Hiredate.Enabled = True
Dim pDataRow As DataRow
pDataRow = mDataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1)
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!SaveAsName = txtfirstname.Text + " " + txtlastname.Text
'pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
cmbcountry.Text = CStr(pDataRow!Country)
Cmbcity.Text = CStr(pDataRow!City)
cmbregion.Text = CStr(pDataRow!Region)
txtpostalcode.Text = CStr(pDataRow!PostalCode)
txtextension.Text = CStr(pDataRow!Extension)
txthomephone.Text = CStr(pDataRow!HomePhone)
txtnotes.Text = CStr(pDataRow!Notes)
'ADDDS
'am adding hereeeeeeeeeeeeeeee
Dim h
h = txtreport.SelectedValue
' MsgBox("value selected id " & h)
' TextBox3.Text = h
pDataRow!ReportsTo = h
'END ADDS
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
btnsave.Enabled = True
end sub
and here is the save button that i click after the button modify has been clicked :
Dim pDataRow As DataRow
pDataRow = mDataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1)
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
pDataRow!Country = cmbcountry.Text
pDataRow!City = Cmbcity.Text
pDataRow!Region = cmbregion.Text
pDataRow!PostalCode = txtpostalcode.Text
pDataRow!HomePhone = txthomephone.Text
pDataRow!Extension = txtextension.Text
pDataRow!Notes = txtnotes.Text
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
pDataRow!SaveAsName = txtfirstname.Text + " " + txtlastname.Text
'ADDDS
'am adding hereeeeeeeeeeeeeeee
' pDataRow!ReportsTo = TextBox4.Text
Dim h
h = txtreport.SelectedValue
' MsgBox("value selected id " & h)
' TextBox3.Text = h
pDataRow!ReportsTo = h
'END ADDS
Try
mDataAdapter.Update(mDataSet)
MsgBox("RECORD SUCCESSFULLY ADDED TO Database", MsgBoxStyle.Information, "Sucess")
Catch eror As Exception
MsgBox("This was an error updating database." & vbCrLf & _
eror.Message)
If txtCurrent.Text = txtCount.Text Then
btnFirst.Enabled = True
btnPrevious.Enabled = True
btnNext.Enabled = False
BtnLast.Enabled = False
End If
End Try
btnsave.Visible = False
cmdRequery.Visible = False
end sub
THE PROBLEM IS THAT I CAN'T MODIFY THE LAST RECORD ONCE I ADD AND TRIES TO MODIFY AFTER ITT
THIS IS THE ADD BUTTON CODE
txtfirstname.Focus()
btnsave.Visible = True
cmdRequery.Visible = True
txtfirstname.Text = ""
txtlastname.Text = ""
txttitlec.Text = "Title Of Courtesy"
txtadress.Text = ""
txtpostalcode.Text = ""
txtextension.Text = ""
txthomephone.Text = ""
txtnotes.Text = ""
cmbregion.Text = ""
Cmbcity.Text = ""
txtreport.Text = ""
txtfirstname.Enabled = True
txtlastname.Enabled = True
txttitlec.Enabled = True
ComboBox1.Enabled = True
cmbcountry.Enabled = True
txtadress.Enabled = True
txtnotes.Enabled = True
txtpostalcode.Enabled = True
txtextension.Enabled = True
txthomephone.Enabled = True
birthdate.Enabled = True
Hiredate.Enabled = True
Cmbcity.Enabled = True
cmbregion.Enabled = True
txtreport.Enabled = True
Dim pDataRow As DataRow
' this is how to instantiate a new DataRow object: from its parent
pDataRow = mDataSet.Tables(0).NewRow()
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Country = cmbcountry.Text
pDataRow!City = Cmbcity.Text
pDataRow!Region = cmbregion.Text
pDataRow!PostalCode = txtpostalcode.Text
pDataRow!HomePhone = txthomephone.Text
pDataRow!Extension = txtextension.Text
pDataRow!Notes = txtnotes.Text
pDataRow!Extension = txtextension.Text
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
'pDataRow!ReportsTo = TextBox4.Text
' the NewRow method called above will just instantiate a new DataRow object,
' it will not append the NewRow to the DataTable
mDataSet.Tables(0).Rows.Add(pDataRow)
txtCount.Text = CStr(CInt(txtCount.Text) + 1)
btnsave.Enabled = True ' let user update the underlying database
txtCurrent.Text = txtCount.Text ' make the current row, the last (recently added) row
btnFirst.Enabled = True
btnPrevious.Enabled = True
btnNext.Enabled = False
BtnLast.Enabled = False
ComboBox1.Text = "Choose Employee Title"
cmbcountry.Text = "Select Country"
txtreport.Text = "Employee Supervisor"
'system date
birthdate.Text = Now()
Hiredate.Text = Now()
' Me.Refresh()
mConn.Close()
End Sub
AND ALSO AFTER THE ADD THE SAME SAVE BUTTON IS CLIKED TO SAVE
Private Sub btnmodify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodify.Click
btnsave.Visible = True
cmdRequery.Visible = True
txtfirstname.Enabled = True
txtlastname.Enabled = True
ComboBox1.Enabled = True
txttitlec.Enabled = True
txtadress.Enabled = True
txtpostalcode.Enabled = True
txtnotes.Enabled = True
txthomephone.Enabled = True
txtextension.Enabled = True
cmbcountry.Enabled = True
Cmbcity.Enabled = True
cmbregion.Enabled = True
birthdate.Enabled = True
Hiredate.Enabled = True
Dim pDataRow As DataRow
pDataRow = mDataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1)
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!SaveAsName = txtfirstname.Text + " " + txtlastname.Text
'pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
cmbcountry.Text = CStr(pDataRow!Country)
Cmbcity.Text = CStr(pDataRow!City)
cmbregion.Text = CStr(pDataRow!Region)
txtpostalcode.Text = CStr(pDataRow!PostalCode)
txtextension.Text = CStr(pDataRow!Extension)
txthomephone.Text = CStr(pDataRow!HomePhone)
txtnotes.Text = CStr(pDataRow!Notes)
'ADDDS
'am adding hereeeeeeeeeeeeeeee
Dim h
h = txtreport.SelectedValue
' MsgBox("value selected id " & h)
' TextBox3.Text = h
pDataRow!ReportsTo = h
'END ADDS
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
btnsave.Enabled = True
end sub
and here is the save button that i click after the button modify has been clicked :
Dim pDataRow As DataRow
pDataRow = mDataSet.Tables(0).Rows(CInt(txtCurrent.Text) - 1)
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
pDataRow!Country = cmbcountry.Text
pDataRow!City = Cmbcity.Text
pDataRow!Region = cmbregion.Text
pDataRow!PostalCode = txtpostalcode.Text
pDataRow!HomePhone = txthomephone.Text
pDataRow!Extension = txtextension.Text
pDataRow!Notes = txtnotes.Text
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
pDataRow!SaveAsName = txtfirstname.Text + " " + txtlastname.Text
'ADDDS
'am adding hereeeeeeeeeeeeeeee
' pDataRow!ReportsTo = TextBox4.Text
Dim h
h = txtreport.SelectedValue
' MsgBox("value selected id " & h)
' TextBox3.Text = h
pDataRow!ReportsTo = h
'END ADDS
Try
mDataAdapter.Update(mDataSet)
MsgBox("RECORD SUCCESSFULLY ADDED TO Database", MsgBoxStyle.Information, "Sucess")
Catch eror As Exception
MsgBox("This was an error updating database." & vbCrLf & _
eror.Message)
If txtCurrent.Text = txtCount.Text Then
btnFirst.Enabled = True
btnPrevious.Enabled = True
btnNext.Enabled = False
BtnLast.Enabled = False
End If
End Try
btnsave.Visible = False
cmdRequery.Visible = False
end sub
THE PROBLEM IS THAT I CAN'T MODIFY THE LAST RECORD ONCE I ADD AND TRIES TO MODIFY AFTER ITT
THIS IS THE ADD BUTTON CODE
txtfirstname.Focus()
btnsave.Visible = True
cmdRequery.Visible = True
txtfirstname.Text = ""
txtlastname.Text = ""
txttitlec.Text = "Title Of Courtesy"
txtadress.Text = ""
txtpostalcode.Text = ""
txtextension.Text = ""
txthomephone.Text = ""
txtnotes.Text = ""
cmbregion.Text = ""
Cmbcity.Text = ""
txtreport.Text = ""
txtfirstname.Enabled = True
txtlastname.Enabled = True
txttitlec.Enabled = True
ComboBox1.Enabled = True
cmbcountry.Enabled = True
txtadress.Enabled = True
txtnotes.Enabled = True
txtpostalcode.Enabled = True
txtextension.Enabled = True
txthomephone.Enabled = True
birthdate.Enabled = True
Hiredate.Enabled = True
Cmbcity.Enabled = True
cmbregion.Enabled = True
txtreport.Enabled = True
Dim pDataRow As DataRow
' this is how to instantiate a new DataRow object: from its parent
pDataRow = mDataSet.Tables(0).NewRow()
pDataRow!FirstName = txtfirstname.Text
pDataRow!LastName = txtlastname.Text
pDataRow!Title = ComboBox1.Text
pDataRow!TitleOfCourtesy = txttitlec.Text
pDataRow!Address = txtadress.Text
pDataRow!SaveAsName = txtsaveas.Text
pDataRow!Country = cmbcountry.Text
pDataRow!City = Cmbcity.Text
pDataRow!Region = cmbregion.Text
pDataRow!PostalCode = txtpostalcode.Text
pDataRow!HomePhone = txthomephone.Text
pDataRow!Extension = txtextension.Text
pDataRow!Notes = txtnotes.Text
pDataRow!Extension = txtextension.Text
pDataRow!BirthDate = birthdate.Text
pDataRow!HireDate = Hiredate.Text
'pDataRow!ReportsTo = TextBox4.Text
' the NewRow method called above will just instantiate a new DataRow object,
' it will not append the NewRow to the DataTable
mDataSet.Tables(0).Rows.Add(pDataRow)
txtCount.Text = CStr(CInt(txtCount.Text) + 1)
btnsave.Enabled = True ' let user update the underlying database
txtCurrent.Text = txtCount.Text ' make the current row, the last (recently added) row
btnFirst.Enabled = True
btnPrevious.Enabled = True
btnNext.Enabled = False
BtnLast.Enabled = False
ComboBox1.Text = "Choose Employee Title"
cmbcountry.Text = "Select Country"
txtreport.Text = "Employee Supervisor"
'system date
birthdate.Text = Now()
Hiredate.Text = Now()
' Me.Refresh()
mConn.Close()
End Sub
AND ALSO AFTER THE ADD THE SAME SAVE BUTTON IS CLIKED TO SAVE