Search code examples
c#winformsms-accessdatagridviewoledb

storing dataset in datagridview to a new access db file c#


Actually I have some data loaded from a access db file in datagridview (in my winform application) and after making changes on dataset I want to save it in a new table of a new access db file through save file dialogue.

I've searched about this but in most of articles they usually tell about updating the dataset in the same access file from which the data has been loaded.but I want the application to create a new access db file with updated data in it. is it possible to do so?

and yup I'm using Oledb technology for accessing data.

thank you


Solution

  • Make a copy from exist db (File.copy), change the connection string and save the changes in this new database.

    public string _strCnn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\dataBase.accdb;";
    
    public void SaveChanges()
    {
        System.IO.File.Copy(@"C:\myFolder\dataBase.accdb;", @"C:\myFolder\NEWdataBase.accdb;");
        _strCnn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\NEWdataBase.accdb;";
    
        //TODO: Save changes 
    }