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