SqlCeCommandBuilder - magiczny konstruktor

0

Zanim zaczniesz czytać temat: nie chodzi o znalezienie błędu.

Otóż: mam na formie DataGridView i stworzoną prostą bazę danych o nazwie kierowcy. Na początku wypełniam DataGridView danymi z tej tabeli i później mam funkcję zapisującą do bazy danych:

            using (SqlCeConnection c = new SqlCeConnection(Properties.Settings.Default.dbConnectionString))
            {
                c.Open();
                using (SqlCeDataAdapter a = new SqlCeDataAdapter(
                    "SELECT * FROM [kierowcy]", c))
                {
                    MessageBox.Show(a.UpdateCommand == null ? "null" : a.UpdateCommand.CommandText); // wyswietla "null"
                    //SqlCeCommandBuilder scb = new SqlCeCommandBuilder(a); // <-- czytaj na dole
                    MessageBox.Show(a.UpdateCommand == null ? "null" : a.UpdateCommand.CommandText); // wyswietla "null"
                    a.Update((DataTable)dataGridView1.DataSource);
                }
            }

odkomentowanie zaznaczonej linii nie zmienia wyświetlonych komunikatów, jednakże po zmianie jakichkolwiek danych w tabelce bez zakomentowanej linii nie działa (pokazuje wyjątek, że brakuje UpdateCommand).

Co w takim razie robi ten konstruktor? Jakim cudem to w ogóle działa?

2

The SqlCeCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one SqlCeDataAdapter or SqlCeCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the SqlCeCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata is retrieved (for example, after the first update), you should call the RefreshSchema() method to update the metadata.

1 użytkowników online, w tym zalogowanych: 0, gości: 1