Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Updating Database Problem

Updating Database Problem

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ccotton333
    wrote on last edited by
    #1

    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?

    D 1 Reply Last reply
    0
    • C ccotton333

      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?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        C Offline
        C Offline
        ccotton333
        wrote on last edited by
        #3

        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.

        D 1 Reply Last reply
        0
        • C ccotton333

          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.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            C Offline
            C Offline
            ccotton333
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups