PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET datagridview does not update in master detail relation

Reply

datagridview does not update in master detail relation

 
Thread Tools Rate Thread
Old 16-06-2006, 08:03 PM   #1
Dirk W
Guest
 
Posts: n/a
Default datagridview does not update in master detail relation


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
  Reply With Quote
Old 17-06-2006, 07:29 AM   #2
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: datagridview does not update in master detail relation

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



  Reply With Quote
Old 19-06-2006, 02:28 PM   #3
Dirk W
Guest
 
Posts: n/a
Default Re: datagridview does not update in master detail relation

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

>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off