R
Rubber Steve
Can someone please tell me what is wrong with my code. The add button works
fine and
when I save the added record is saved but for some reason when I edit and
save the
information that I edited will not save. I got my code straight out of my
old VB.net book.
The add button code whick works is:
If btnAdd.Text = "Cancel" Then
LockTextBoxes()
EnableNav()
btnSave.Enabled = False
btnAdd.Text = "&Add"
RejectChanges()
mblnAdding = False
Else
UnlockTextBoxes()
txtSearch.Clear()
txtPID.Clear()
txtPrice.Clear()
txtCost.Clear()
txtBrand.Clear()
txtDelivery.Clear()
txtDesc.Clear()
txtQuan.Clear()
txtSID.Clear()
txtPID.Focus()
DisableNav()
btnSave.Enabled = True
btnAdd.Text = "Cancel"
mblnAdding = True
End If
And the edit button is:
UnlockTextBoxes()
DisableNav()
btnSave.Enabled = True
btnAdd.Text = "Cancel"
And Finally my save button which saves the added record but won't update an
edited
record is:
If mblnAdding Then
Try
Dim newRow As DataRow = DsProd1.Product.NewRow
newRow("Model") = txtPID.Text
newRow("ListPrice") = txtPrice.Text
newRow("Cost") = txtCost.Text
newRow("Brand") = txtBrand.Text
newRow("Fees") = txtDelivery.Text
newRow("Description") = txtDesc.Text
newRow("QuantityOnHand") = txtQuan.Text
newRow("SupplierID") = txtSID.Text
DsProd1.Product.Rows.Add(newRow)
Catch exc As Exception
MessageBox.Show("Unable to Add the Product." &
ControlChars.NewLine &
exc.Message, "Product")
End Try
mblnAdding = False
End If
LockTextBoxes()
EnableNav()
btnSave.Enabled = False
btnAdd.Text = "&Add"
mblnIsDirty = True
If mblnIsDirty Then
If MessageBox.Show("Do you want to save the Changes?",
"Product",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Try
dbProd.Update(DsProd1, "Product")
Catch
MessageBox.Show("Error saving the File", "Product")
End Try
End If
End If
I don't understand why it's not working. Any insight would be much
appreciated.
fine and
when I save the added record is saved but for some reason when I edit and
save the
information that I edited will not save. I got my code straight out of my
old VB.net book.
The add button code whick works is:
If btnAdd.Text = "Cancel" Then
LockTextBoxes()
EnableNav()
btnSave.Enabled = False
btnAdd.Text = "&Add"
RejectChanges()
mblnAdding = False
Else
UnlockTextBoxes()
txtSearch.Clear()
txtPID.Clear()
txtPrice.Clear()
txtCost.Clear()
txtBrand.Clear()
txtDelivery.Clear()
txtDesc.Clear()
txtQuan.Clear()
txtSID.Clear()
txtPID.Focus()
DisableNav()
btnSave.Enabled = True
btnAdd.Text = "Cancel"
mblnAdding = True
End If
And the edit button is:
UnlockTextBoxes()
DisableNav()
btnSave.Enabled = True
btnAdd.Text = "Cancel"
And Finally my save button which saves the added record but won't update an
edited
record is:
If mblnAdding Then
Try
Dim newRow As DataRow = DsProd1.Product.NewRow
newRow("Model") = txtPID.Text
newRow("ListPrice") = txtPrice.Text
newRow("Cost") = txtCost.Text
newRow("Brand") = txtBrand.Text
newRow("Fees") = txtDelivery.Text
newRow("Description") = txtDesc.Text
newRow("QuantityOnHand") = txtQuan.Text
newRow("SupplierID") = txtSID.Text
DsProd1.Product.Rows.Add(newRow)
Catch exc As Exception
MessageBox.Show("Unable to Add the Product." &
ControlChars.NewLine &
exc.Message, "Product")
End Try
mblnAdding = False
End If
LockTextBoxes()
EnableNav()
btnSave.Enabled = False
btnAdd.Text = "&Add"
mblnIsDirty = True
If mblnIsDirty Then
If MessageBox.Show("Do you want to save the Changes?",
"Product",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
Try
dbProd.Update(DsProd1, "Product")
Catch
MessageBox.Show("Error saving the File", "Product")
End Try
End If
End If
I don't understand why it's not working. Any insight would be much
appreciated.