By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,642 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,642 IT Pros & Developers. It's quick & easy.

Save Problem in VB

P: n/a
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.

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Rubber Steve" <ru*********@steverino.com.nospam> wrote in message
news:2j*********************@twister.tampabay.rr.c om...
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.

Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.