Results 1 to 11 of 11

Thread: VB Lessons

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    VB Lessons

    I am working on the VB 2005 Express Lessons for Beginers that can be found on the MS web site for VB. The current video is #9 on DataBinding. I followed the tutorial and everything works fine except for the updating of the database. It doesn't update. Any thoughts of the top of your collective heads?

  2. #2
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: VB Lessons

    Any thoughts of the top of your collective heads?
    You did something wrong.

    You need to give us a little more detail if you want a better answer unfortunately. Does it give you any error? Does it appear to update but the update is not in the database? Can you give us a little more detail? Also post your code for the update section.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: VB Lessons

    I added a new project, database etc. as instructed by the video. The code was automatically generated by dragging the MyCompanyDataSet over to Form1. The code is shown below. As you know the CustomerBindingNavigator was added. This includes the "Save" option. When I change an element say First Name and then hit Save the database is not updated.

    Code Below:
    Public Class Form1

    Private Sub CustomerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Me.Validate()
    Me.CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.MyCompanyDataSet.Customer)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'MyCompanyDataSet.Customer' table. You can move, or remove it, as needed.
    Me.CustomerTableAdapter.Fill(Me.MyCompanyDataSet.Customer)
    'TODO: This line of code loads data into the 'MyCompanyDataSet.Customer' table. You can move, or remove it, as needed.
    Me.CustomerTableAdapter.Fill(Me.MyCompanyDataSet.Customer)

    End Sub

    Private Sub CustomerBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomerBindingNavigatorSaveItem.Click
    Me.Validate()
    Me.CustomerBindingSource.EndEdit()
    Me.CustomerTableAdapter.Update(Me.MyCompanyDataSet.Customer)

    End Sub
    End Class

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: VB Lessons

    I don't see anywhere in that code that contains a CommandBuilder, which can autogenerate the insert,update, and delete statements when calling Update. I haven't ever worked with a "TableAdapter", however, but I know this is the case with Data Adapters, so not sure if there is something similar for it.

  5. #5
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: VB Lessons

    Are you sure it is not being updated? Bear in mind that if you rerun the project then you will continue to see the OLD info. The new info should now be updated in the databasefile located in your BIN directory. Each time you rerun your project you are replacing the datafile in the bin directory. Therefore, run your project and change something and save it. Then open your bin directory and run the executable in there and see if your database contains the updated info.
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Lessons

    Quote Originally Posted by gigemboy
    I don't see anywhere in that code that contains a CommandBuilder, which can autogenerate the insert,update, and delete statements when calling Update. I haven't ever worked with a "TableAdapter", however, but I know this is the case with Data Adapters, so not sure if there is something similar for it.
    Tabl;eAdapters are created along with typed DataSets, so they already have the SQL code needed to save changes. If I'm not mistaken you cannot create a TableAdapter yourself, or at least you aren't supposed to. They should be generated by the IDE froma data source. They are to typed DataSets what DataAdapters are to untyped DataSets.

    I also notice that your Load event handler seems to be Filling the same table twice.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    7

    Re: VB Lessons

    Thanks nothingofvalue. The .exe app does indeed update the database. So why do I see the old data when running from within the vb editor? Thanks for you help!

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Lessons

    This question seems to be being asked a lot lately, assuming that it's the same situation.

    http://www.vbforums.com/showthread.php?t=386623
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: VB Lessons

    Because it pulls the database file from your project folder but the modified copy is saved in your bin directory. Therefore the original file is left unchanged. You will only see an issue with it while developing. Once the application is finished everything will work as expected.
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  10. #10
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: VB Lessons

    I had the same problem.
    I had to build the program and then run it from the exe.
    All good

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Lessons

    Quote Originally Posted by toecutter
    I had the same problem.
    I had to build the program and then run it from the exe.
    All good
    You may have done that, but you didn't have to.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width