datagridview is not updating in master-detail relation

datagridview is not updating in master-detail relation

Post by Dirk » Sat, 17 Jun 2006 19:25:29

I setup a simple database with a master and a detail table. Both are
connected via a datarelation. Data of each table is shown in a
datagridview (dgLektion and dgLektionlernkarten). When I start the app
for the first time, everything works fine: all master rows are shown
in dgLektion and the appropriate child rows of the first selected
master row are shown in dgLektionlernkarten.

But if I click e.g. on the 2nd row of the master table,
dgLektionlernkarten is not updated and therefore still shows the child
rows of the previous selected master row.

Even more strange for me is that if I click on the column header in
dgLektion and so change the order of the master rows, than
dgLektionlernkarten is updating correctly and showing the child rows
for the now topmost master row.

Can anyone give me a hint what I am doing wrong?


SqlCommand selCommandLektion = conn.CreateCommand();
selCommandLektion.CommandText = "SELECT * FROM Lektion";
SqlDataAdapter daLektion = new SqlDataAdapter(selCommandLektion);
daLektion.Fill(dsLCard, "Lektion");

SqlCommand selCommandLektionLernkarten = conn.CreateCommand();
selCommandLektionLernkarten.CommandText = "SELECT * FROM
SqlDataAdapter daLektionLernkarten = new
daLektionLernkarten.Fill(dsLCard, "LektionLernkarten");


dgLektion.DataSource = dsLCard.Tables["Lektion"];
dgLektionLernkarten.DataSource =
dgLektionLernkarten.DataMember = "relLektion_LektionLernkarten";