Save Problem in VB

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.
 
O

One Handed Man \( OHM - Terry Burns \)

Your code looks ok to me, do you have an Insert Command set up for your
Connection/DataAdapter setup?

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
C

Cor Ligthert

Hi Rubber,

OHM did bring me on the idea for this question, you said, the first one goes
right, is that a new one (an insert) and does the update go wrong.

To say it in another way, how did you create your database stuff, was that
with draging a dataadapter to your form?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top