2

I have a problem that drives me crazy... I have a local database (.sdf) on my PC en a database on the internet (MySQL), both with same structure. I first load data from the internet in the dataset via the dataadapter and secondly I load some local data in the dataset.

Now I want to store the data from internet also in the local database, I tried it with the Update statement. This has to work, but everytime I run the program (debug) and I went back to the local database (via the database explorer, right click on table, Show Table data...), the internet data has not been saved!

To be clear I do see both data (local en from internet) in my dataGrid1.

What do you think is the problem?

        klantenTableAdapter.ClearBeforeFill = false;

        DigiLocalDataSet dataset = new DigiLocalDataSet();

        string MyConString = "SERVER=server;" +
                    "DATABASE=db;" +
                    "UID=uid;" +
                    "PASSWORD=pass;";
        string sql = "SELECT klantnr, geslacht, voorletters, roepnaam, achternaam, tussenvoegsel, straat, huisnr, subhuisnr, postcode, plaats, telthuis, telmobiel, email, geboortedatum FROM klanten ORDER BY roepnaam";

        MySqlConnection connection = new MySqlConnection(MyConString);

        MySqlCommand cmdSel = new MySqlCommand(sql, connection);

        MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);


        //Fill from internet
        da.Fill(dataset.klanten);


        //Fill from local database
        klantenTableAdapter.Fill(dataset.klanten);

        klantenTableAdapter.Update(dataset.klanten);

        //dataset.AcceptChanges();

        this.DataContext = dataset.klanten.DefaultView;

Thanks in advance!

Lars Boele
  • 375
  • 2
  • 10
  • 26
  • Your 'internet' rows have the _Unchanged_ status. Better to copy the records to a new Table, maybe keep 2 Datasets. – H H Jun 10 '11 at 19:41
  • If what Henk says is true (very probable ;-)) then try to edit some "internet" data. Those rows should then become visible after the Update. – Dabblernl Jun 10 '11 at 23:06
  • That doesn't work, in fact what I want to do is to copy the internet MySQL table data to an exactly the same table on my local machine. I thought this is a right way, but maybe it isn't. Does one of you guys have an idea to make this hapen?? – Lars Boele Jun 12 '11 at 13:19

2 Answers2

0

New to this, but don't you need to call SaveChanges too to commit it to the database?

CYMR0
  • 566
  • 6
  • 16
0

It seems that de db reference uses a relative path. The Dataset wizard proposes to copy the database to your output directory. However in the Server explorer you are still examining the original database. Could that be it? ;-)

Dabblernl
  • 15,831
  • 18
  • 96
  • 148