PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
datagridview does not update in master detail relation
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
datagridview does not update in master detail relation
![]() |
datagridview does not update in master detail relation |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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? Code: 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 LektionLernkarten"; SqlDataAdapter daLektionLernkarten = new SqlDataAdapter(selCommandLektionLernkarten); daLektionLernkarten.Fill(dsLCard, "LektionLernkarten"); dsLCard.Relations.Add("relLektion_LektionLernkarten", dsLCard.Tables["Lektion"].Columns["ID"], dsLCard.Tables["LektionLernkarten"].Columns["IDLektion"]); dgLektion.DataSource = dsLCard.Tables["Lektion"]; dgLektionLernkarten.DataSource = dsLCard.Tables["Lektion"].DefaultView; dgLektionLernkarten.DataMember = "relLektion_LektionLernkarten"; Thanks Dirk |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Dirk,
Have a look at the bottom of this sample. http://www.vb-tips.com/default.aspx...3b-8b8620d93761 (And be aware that you are using the defaultview, what I would not do) (be aware that the difference in this sample between VB and C# is only the declaration, the ending ; and tho use [] for a property instead of () ) I hope this helps, Cor "Dirk W" <dirk.weber@fullfeedback.com> schreef in bericht news:s106925plvut11j2geum25fpf40rlprov2@4ax.com... >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? > > Code: > > 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 > LektionLernkarten"; > SqlDataAdapter daLektionLernkarten = new > SqlDataAdapter(selCommandLektionLernkarten); > daLektionLernkarten.Fill(dsLCard, "LektionLernkarten"); > > > dsLCard.Relations.Add("relLektion_LektionLernkarten", > dsLCard.Tables["Lektion"].Columns["ID"], > dsLCard.Tables["LektionLernkarten"].Columns["IDLektion"]); > > dgLektion.DataSource = dsLCard.Tables["Lektion"]; > dgLektionLernkarten.DataSource = > dsLCard.Tables["Lektion"].DefaultView; > dgLektionLernkarten.DataMember = "relLektion_LektionLernkarten"; > > > Thanks > Dirk |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Cor,
now it works perfect! Thanks Btw. VB-Tips is a great side! Dirk On Sat, 17 Jun 2006 08:29:01 +0200, "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote: >Dirk, > >Have a look at the bottom of this sample. > >http://www.vb-tips.com/default.aspx...3b-8b8620d93761 > >(And be aware that you are using the defaultview, what I would not do) > >(be aware that the difference in this sample between VB and C# is only the >declaration, the ending ; and tho use [] for a property instead of () ) > >I hope this helps, > >Cor > >"Dirk W" <dirk.weber@fullfeedback.com> schreef in bericht >news:s106925plvut11j2geum25fpf40rlprov2@4ax.com... >>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? >> >> Code: >> >> 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 >> LektionLernkarten"; >> SqlDataAdapter daLektionLernkarten = new >> SqlDataAdapter(selCommandLektionLernkarten); >> daLektionLernkarten.Fill(dsLCard, "LektionLernkarten"); >> >> >> dsLCard.Relations.Add("relLektion_LektionLernkarten", >> dsLCard.Tables["Lektion"].Columns["ID"], >> dsLCard.Tables["LektionLernkarten"].Columns["IDLektion"]); >> >> dgLektion.DataSource = dsLCard.Tables["Lektion"]; >> dgLektionLernkarten.DataSource = >> dsLCard.Tables["Lektion"].DefaultView; >> dgLektionLernkarten.DataMember = "relLektion_LektionLernkarten"; >> >> >> Thanks >> Dirk > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

