Need some logic help

M

Mike

Hey guys I need some help with updateing an access database. I used OleDB
controls to set up my connection, adapter, and dataset.

The access table I am trying to update has these columns in this order:

CustomerID
Username
Password
Email
CustomerName
BillingAddress
ZipCode
PhoneNumber

I create my dataset and grab all the columns, but really all I am interested
in is being able to update CustomerName, BillingAddress, ZipCode, and
PhoneNumber.

The problem I am having is for example lets say I want to update the first
record's zip code. I enter in the new zipcode and click on my update record
button and it updates just the zip code for the first record, but then jumps
all the way down to the last record and copies the address in the last
record to the last records zip code, and phone number columns. Any ideas as
to why its doing this??

Thanks for any help!

Mike

Here is my code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
daCustomers.Fill(CustomersDS1)

End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Dim CommandBuilder As New OleDb.OleDbCommandBuilder(daCustomers)
Dim POS As Integer


With BindingContext(CustomersDS1, "Customers")
.Position = .Count - 1
POS = .Position
End With



CustomersDS1.Tables("Customers").Rows(POS).Item(4) = txtName.Text
CustomersDS1.Tables("Customers").Rows(POS).Item(5) = txtAddress.Text
CustomersDS1.Tables("Customers").Rows(POS).Item(6) = txtZip.Text
CustomersDS1.Tables("Customers").Rows(POS).Item(7) = txtPhone.Text

daCustomers.Update(CustomersDS1, "Customers")

End Sub

Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFirst.Click

BindingContext(CustomersDS1, "Customers").Position = 0

End Sub

Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrev.Click

With BindingContext(CustomersDS1, "Customers")
If .Position > 0 Then .Position = .Position - 1
End With

End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click

With BindingContext(CustomersDS1, "Customers")
If .Position < .Count - 1 Then .Position = .Position + 1
End With

End Sub

Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLast.Click
With BindingContext(CustomersDS1, "Customers")
.Position = .Count - 1
End With

End Sub


End Class
 
G

Gerald Hernandez

Mike,

Well, I haven't used the database stuff much in .NET, but from what I can
glean, it is doing exactly what you are telling it to do.
If you look at the btnUpdate_Click method:
With BindingContext(CustomersDS1, "Customers")
[GH] The following line sets the current position in your dataset to the
Last record
.Position = .Count - 1

[GH] This line gets a copy of the current position, which is now the last
record.
POS = .Position
End With

[GH] This line updates Row(POS), which is the last row, based on POS.
CustomersDS1.Tables("Customers").Rows(POS).Item(4) = txtName.Text

I think the only reason your initial record is being updated "correctly" is
due to the fact that your dataset is bound.
Possibly you wanted those above lines swapped. Store the current position
first, then move to the end. But I still don't see where that would be
necessary or useful in this case.

Gerald
 

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