471,624 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Need some logic help

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:


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

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!


Here is my code:

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

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
Jul 21 '05 #1
1 1250

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.

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mike | last post: by
25 posts views Thread by Bjørn T Johansen | last post: by
7 posts views Thread by Jack Addington | last post: by
16 posts views Thread by MS newsgroup | last post: by
10 posts views Thread by David Thielen | last post: by
9 posts views Thread by SAL | last post: by
15 posts views Thread by bruno.desthuilliers | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.