I'm using mysql database..I have forms setup main form has datagrid..you can add to this datagrid and save to datbase with my add form and it works fine. I can delete from the datagrid and it works fine...when I select an account to edit is when I have my issue...form edit brings up the selected account but when I save my changes it doesn't save to the selected account it changes my first account in the database...Help...here is a sample of my code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' 'Save changes to database and exit
Dim intResponse As String
intResponse = MsgBox("Do you want to SAVE Changes to this record?", vbOKCancel, "Save?")
If intResponse = vbOK Then

PbCustomerDS.customer(0).Address_Line1 = Address_Line1TextBox.Text
PbCustomerDS.customer(0).Location = LocationTextBox.Text
PbCustomerDS.customer(0).Attention = AttentionTextBox.Text
PbCustomerDS.customer(0).City = CityTextBox.Text
PbCustomerDS.customer(0).State = StateTextBox.Text
PbCustomerDS.customer(0).Zip = ZipTextBox.Text
PbCustomerDS.customer(0).Phone = PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Bill_To = Bill_ToTextBox.Text
PbCustomerDS.customer(0).Attention_2 = Attention_2TextBox.Text
PbCustomerDS.customer(0).B_address = B_addressTextBox.Text
PbCustomerDS.customer(0).B_City = (B_CityTextBox.Text)
PbCustomerDS.customer(0).B_State = B_StateTextBox.Text
PbCustomerDS.customer(0).B_Zip = B_ZipTextBox.Text
PbCustomerDS.customer(0).B_Phone = B_PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Comments = CommentsTextBox.Text
PbCustomerDS.customer(0).Updated = UpdatedLabel1.Text

Me.Validate()
Me.CustomerBindingSource.DataSource.GetType()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(PbCustomerDS)
Me.TableAdapterManager.UpdateAll(PbCustomerDS)

Me.Close()
End If
If vbCancel Then
Exit Sub
End If

End Sub

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

can someone please help me with my issue?

I'm using mysql database..I have forms setup main form has datagrid..you can add to this datagrid and save to datbase with my add form and it works fine. I can delete from the datagrid and it works fine...when I select an account to edit is when I have my issue...form edit brings up the selected account but when I save my changes it doesn't save to the selected account it changes my first account in the database...Help...here is a sample of my code
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
' 'Save changes to database and exit
Dim intResponse As String
intResponse = MsgBox("Do you want to SAVE Changes to this record?", vbOKCancel, "Save?")
If intResponse = vbOK Then

PbCustomerDS.customer(0).Address_Line1 = Address_Line1TextBox.Text
PbCustomerDS.customer(0).Location = LocationTextBox.Text
PbCustomerDS.customer(0).Attention = AttentionTextBox.Text
PbCustomerDS.customer(0).City = CityTextBox.Text
PbCustomerDS.customer(0).State = StateTextBox.Text
PbCustomerDS.customer(0).Zip = ZipTextBox.Text
PbCustomerDS.customer(0).Phone = PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Bill_To = Bill_ToTextBox.Text
PbCustomerDS.customer(0).Attention_2 = Attention_2TextBox.Text
PbCustomerDS.customer(0).B_address = B_addressTextBox.Text
PbCustomerDS.customer(0).B_City = (B_CityTextBox.Text)
PbCustomerDS.customer(0).B_State = B_StateTextBox.Text
PbCustomerDS.customer(0).B_Zip = B_ZipTextBox.Text
PbCustomerDS.customer(0).B_Phone = B_PhoneMaskedTextBox.Text
PbCustomerDS.customer(0).Comments = CommentsTextBox.Text
PbCustomerDS.customer(0).Updated = UpdatedLabel1.Text

Me.Validate()
Me.CustomerBindingSource.DataSource.GetType()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(PbCustomerDS)
Me.TableAdapterManager.UpdateAll(PbCustomerDS)

Me.Close()
End If
If vbCancel Then
Exit Sub
End If

End Sub

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

can someone please help me with my issue?

Well the reason you are getting the first record changing is because you've hardcoded that the routine will change the first record i.e. the zero index record on the data grid.....

Instead of using

PbCustomerDS.Customer(0).

you need to identify the index of the currently selected row and pass it in:

dim intCurrentRow as integer
.......
PbCustomerDS.Customer(intCurrentRow).

There are a few hints as to how you get the CURRENT ROW in this post. (Look up the properties of a datagrid if you are still stuck)

Well the reason you are getting the first record changing is because you've hardcoded that the routine will change the first record i.e. the zero index record on the data grid.....

Instead of using

PbCustomerDS.Customer(0).

you need to identify the index of the currently selected row and pass it in:

dim intCurrentRow as integer
.......
PbCustomerDS.Customer(intCurrentRow).

There are a few hints as to how you get the CURRENT ROW in this post. (Look up the properties of a datagrid if you are still stuck)

Thanks I tried it..but still saves to the first one in the database..I'll keep trying

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.