We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,303 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problem updating form after data is added to database

so i have a working ish program now, when i add the record it saves and returns the save message box as it should and is viewable in the database where it saves to, but it is not viewable in the text boxes when looking back at the form until i close program and re open it, then i can see the record stored in the database, it just wont update the form, but it should, here is the code whats going on here (probably easy fix just wont make sense in my head)

Private Sub btncommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncommit.Click

        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsnewrow As DataRow

        da.Fill(ds, "Appointment")

        dsnewrow = ds.Tables("tblCustomers").NewRow()

        dsnewrow.Item("CustomerID") = txtcustomerid.Text
        dsNewRow.Item("GroupName") = txtgroupname.Text
        dsNewRow.Item("Forename") = txtforename.Text
        dsNewRow.Item("Surname") = txtsurname.Text
        dsNewRow.Item("DateOfBirth") = txtdob.Text
        dsNewRow.Item("Address") = txtaddress.Text
        dsNewRow.Item("Town") = txttown.Text
        dsNewRow.Item("County") = txtcounty.Text
        dsNewRow.Item("Postcode") = txtpostcode.Text
        dsNewRow.Item("Telephone") = txttelephone.Text


        ds.Tables("tblCustomers").Rows.Add(dsNewRow)
        da.Fill(ds, "tblCustomers")
        da.Update(ds, "tblCustomers")

        MsgBox("New Record added to the Database")

        btncommit.Enabled = False
        btnsavecustomer.Enabled = True
        btneditcustomer.Enabled = True
        btndeletecustomer.Enabled = True

        ' End If


    End Sub
Attachments screenshot.png 659.19KB
2
Contributors
2
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
3
Views
Question
Answered
nomorelogic
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I believe your Dataset Update Command should come before your DataAdapter Fill Command. You would be just refilling anything in the Database Table to the DataSet wiping out your record during runtime. That's why when you restart it shows up.

ds.Tables("tblCustomers").Rows.Add(dsNewRow)        
da.Update(ds, "tblCustomers")
da.Fill(ds, "tblCustomers")

I also do not see where you are using a BindingSource for the TextBoxes then ResetBindings(False). It would make it easier but it isn't necessary.

Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
Skill Endorsements: 0

yeah thanks, i looked back at it and realized in the end, thanks a lot though it will help careless idiots like me in the future :)

nomorelogic
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Phasma

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0720 seconds using 2.7MB