Updating Database Problem
-
I have a form that uses a comboboxes selected index value to populate textboxes, but when I try to edit the information, it doesn't save the information back to the database. Any ideas or suggestions would be appreciated?
-
I have a form that uses a comboboxes selected index value to populate textboxes, but when I try to edit the information, it doesn't save the information back to the database. Any ideas or suggestions would be appreciated?
Your going to have to supply much more information about your problem and what and how your doing things. So far, it looks like you have combo boxes bound to text boxes, but nothing about how your getting your data from the database, what code you have writing data back to the database, what version of VB your using, just to name a few things. Code samples of these things would help us out greatly! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Your going to have to supply much more information about your problem and what and how your doing things. So far, it looks like you have combo boxes bound to text boxes, but nothing about how your getting your data from the database, what code you have writing data back to the database, what version of VB your using, just to name a few things. Code samples of these things would help us out greatly! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
On load of form, The combobox is filled with the information(Ex. Fullname), which is done by a dataset. Then based on its selected index value there are textboxes that are data-bound based on that(Ex. Firstname, lastname,address). This is done by another query which the select statement is like this: Select * from TCust Where (Fullname=?) After the textboxes are populated with the correct data, Then you can select the Edit button which allows you to actually change the information, but when you go to save the changes whether it be by the same dataset that populated the textboxes or by a declared dataset that gets the changes from the dataset that filled the textboxes, It won't save the changes and update the table. I've tried just about everything I can think of, and everything I come up with takes a lot of steps and I'm thinking that there has to be an easier way of doing this. I hope this helps you.
-
On load of form, The combobox is filled with the information(Ex. Fullname), which is done by a dataset. Then based on its selected index value there are textboxes that are data-bound based on that(Ex. Firstname, lastname,address). This is done by another query which the select statement is like this: Select * from TCust Where (Fullname=?) After the textboxes are populated with the correct data, Then you can select the Edit button which allows you to actually change the information, but when you go to save the changes whether it be by the same dataset that populated the textboxes or by a declared dataset that gets the changes from the dataset that filled the textboxes, It won't save the changes and update the table. I've tried just about everything I can think of, and everything I come up with takes a lot of steps and I'm thinking that there has to be an easier way of doing this. I hope this helps you.
ccotton333 wrote: Select * from TCust Where (Fullname=?) Are you editing the Fullname? If so, your aparently invalidating your Primary Key which is what is being used to uniquely identify the record your editing. If you modify this key, your UPDATE SQL statements won't work because you're trying to update a record that doesn't exist, as specified by your new primary key. Like I said, without seeing the code your using, it's nearly impossible to tell you what's going wrong. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
ccotton333 wrote: Select * from TCust Where (Fullname=?) Are you editing the Fullname? If so, your aparently invalidating your Primary Key which is what is being used to uniquely identify the record your editing. If you modify this key, your UPDATE SQL statements won't work because you're trying to update a record that doesn't exist, as specified by your new primary key. Like I said, without seeing the code your using, it's nearly impossible to tell you what's going wrong. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Well the code is kind of long: Public Class frmMain4 Inherits System.Windows.Forms.Form Private Sub cboFullname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFullname.SelectedIndexChanged Dscustinfo21.Clear() dbCustInfo.SelectCommand.Parameters("fullname").Value = cboFullname.Text dbCustInfo.Fill(Dscustinfo21) End Sub Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click 'allows you to edit a record If btnEdit.Text = "Edit" Then UnlockTextBoxes() btnSave.Enabled = True btnEdit.Text = "Cancel" ElseIf btnEdit.Text = "Cancel" Then LockTextBoxes() btnSave.Enabled = False End If End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'saves the record LockTextBoxes() btnSave.Enabled = False btnEdit.Text = "Edit" Try dbCustInfo.Update(Dscustinfo21, "tcust") Catch ex As Exception MsgBox("Update didn't work.") End Try MsgBox("Update must have worked.") End Sub Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click 'closes the program Me.Close() End Sub Private Sub UnlockTextBoxes() txtLastName.ReadOnly = False txtName.ReadOnly = False txtAddress.ReadOnly = False txtAddress1.ReadOnly = False txtCity.ReadOnly = False txtState.ReadOnly = False txtZip.ReadOnly = False txtCountry.ReadOnly = False txtHomePhone.ReadOnly = False txtWorkPhone.ReadOnly = False txtMobile.ReadOnly = False txtPager.ReadOnly = False txtEmail.ReadOnly = False End Sub Private Sub LockTextBoxes() txtLastName.ReadOnly = True txtName.ReadOnly = True txtAddress.ReadOnly = True txtAddress1.ReadOnly = True txtCity.ReadOnly = True txtState.ReadOnly = True txtZip.ReadOnly = True txtCountry.ReadOnly = True txtHomePhone.ReadOnly = True txtWorkPhone.ReadOnly = True txtMobile.ReadOnly = True txtPager.ReadOnly = True txtEmail.ReadOnly = True End Sub Private Sub frmMain4_Load(ByVal sender As System.Object, ByVal