none
VB.Net & WPF - Can Get data from access database and insert a record to the dataset but I cant figure out how to save to the original database! RRS feed

  • Question

  • For the life of me!....

    The only database knowledge I have is using MS Access 2007 but now I want to use it in Visual Basic 2008.net and Windows Presentation Foundation (Which I'm very fresh). I've successfully linked my access database and retrieved data and I can even add a new row and retrieve that data but when I end the program and have a look in the original Access DB the changes are not reflected!!

            Dim adaptor As New DataSet1TableAdapters.PeopleTableAdapter
            Dim table As New DataSet1.PeopleDataTable
            Dim data As New DataSet1
    
            adaptor.Adapter.AcceptChangesDuringUpdate = True
            adaptor.Adapter.AcceptChangesDuringFill = True
    
            Dim peopleRow As DataSet1.PeopleRow
            peopleRow = table.NewPeopleRow()
            peopleRow.ID = 4
            peopleRow.Name = "Le-roy"
            peopleRow.Age = 22
    
            table.Rows.Add(peopleRow)
            adaptor.Fill(data.People)
            adaptor.Update(table)
    I've tried for the last 10 hours and I'm stumped! I've gone through the msdn stuff and everything I could find on google much of which I could not make complete sense of. Could someone please help me out? This should be easy!!
    Thursday, March 11, 2010 10:27 PM

Answers

  • Leroy,

    When you create a strongly typed DataSet in Visual Studio using a connection to an Access database, Visual Studio prompts you and asks whether or not you want to add the Access database to your project.  It's been a while since I dug into all the ins and outs of the options but from what I remember, saying Yes to the dialog causes Visual Studio to do a number of things:

    1.)  Visual Studio copies the original database to your project's directory and adds a reference to this copy in your project.

    2.)  Visual Studio will copy the database from your project's directory to the application executable directory each time you build your project.  You can specify another behavior by selecting the database in Solution Explorer, then changing the value for Copy to Output Directory in the Properties window.  Many developers change Copy to Output to Copy If Newer during the development process so they can see that their code modified the contents of the database.  Remember that this approach requires that you look at the copy of the database in the executable directory to see those changes.

    3.)  Visual Studio re-writes the original connection string to use a relative path using |DataDirectory|, so that your application will load the database in the application executable's directory.

    I hope this information proves helpful.

    David Sceppa
    • Marked as answer by Leroy30 Wednesday, March 17, 2010 6:47 AM
    Monday, March 15, 2010 10:27 PM
    Moderator

All replies

  • Leroy,

    When you create a strongly typed DataSet in Visual Studio using a connection to an Access database, Visual Studio prompts you and asks whether or not you want to add the Access database to your project.  It's been a while since I dug into all the ins and outs of the options but from what I remember, saying Yes to the dialog causes Visual Studio to do a number of things:

    1.)  Visual Studio copies the original database to your project's directory and adds a reference to this copy in your project.

    2.)  Visual Studio will copy the database from your project's directory to the application executable directory each time you build your project.  You can specify another behavior by selecting the database in Solution Explorer, then changing the value for Copy to Output Directory in the Properties window.  Many developers change Copy to Output to Copy If Newer during the development process so they can see that their code modified the contents of the database.  Remember that this approach requires that you look at the copy of the database in the executable directory to see those changes.

    3.)  Visual Studio re-writes the original connection string to use a relative path using |DataDirectory|, so that your application will load the database in the application executable's directory.

    I hope this information proves helpful.

    David Sceppa
    • Marked as answer by Leroy30 Wednesday, March 17, 2010 6:47 AM
    Monday, March 15, 2010 10:27 PM
    Moderator
  • Woohoo that was it!!

    Thanks heaps for that you really saved my life! (well, you know)

    Cheers.

    Wednesday, March 17, 2010 6:48 AM
  • No worries, Leroy.  Thanks for letting us know that response helped.
    David Sceppa
    Wednesday, March 17, 2010 4:52 PM
    Moderator
  • Woohoo that was it!!

    Thanks heaps for that you really saved my life! (well, you know)

    Cheers.


    Wow, it also helps me a lot. It saved my life too.
    Friday, July 30, 2010 2:36 AM
  • how can i update the data ? please help i have tried almost 30 days
    Wednesday, August 20, 2014 10:28 AM