Solved

2 DataGrids(parent/child) of a Relationel tables

Posted on 2004-10-08
12
382 Views
Last Modified: 2010-04-15
Hi,

I have 2 talbes in a DataSet, and made a DataRelation between the 2 tables in the DataSet.

One of the Tables are displayed in a datagrid, and when one of them is selected in the datagrid I want its childrows to be displayed in a second datagrid.

How can I get only the related data into the second datagrid, or maybe use a filter, to only get the child rows??

I totally blank on this one.

I use ByteFX to connect to a mysql database, but the same problem is there if MSSQL :-(

Here are my code:
private void Form1_Load(object sender, System.EventArgs e)
{
    MySqlConnection thisConnection = new MySqlConnection("Server=syska.dk; Username=root; Password=supermand; Database=c-sharp;");
   
    MySqlDataAdapter thisPollAdapter = new MySqlDataAdapter("SELECT * FROM poll", thisConnection);

    MySqlDataAdapter thisOptionAdapter = new MySqlDataAdapter("SELECT * FROM pollOption", thisConnection);

    thisPollAdapter.Fill(thisDataSet, "first");

    thisOptionAdapter.Fill(thisDataSet, "second");
   
    dataGrid.DataSource = thisDataSet.Tables["first"];

    DataRelation thisRelation = new DataRelation("thisRelation", thisDataSet.Tables[0].Columns["pollId"], thisDataSet.Tables[1].Columns["pollId"]);

    // MessageBox.Show( thisDataSet.Tables[1].ParentRelations. );

    // her skal de columns smides ind som passer til det ID som er valgt i det anden datagrid
    // dataGrid1.DataSource =
}

As you can see, I havent made anything fancy yet. Are this the right way to go, or are there are better way of doing this, I dont want to get all the data every time, I choose a new row in the first datagrid..

kind regards
Mikael Syska
0
Comment
Question by:syska
  • 6
  • 4
12 Comments
 
LVL 8

Expert Comment

by:gregasm
ID: 12260178
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12260187
Do you have Yukon? It is still in Beta and probably should not be released into Production yet! haha..

But what are you trying to do?

1. Keep the data TOTALLY UP TO DATE AT ALL TIMES AT ALL COSTS.

2. Keep the data clean by IMPLEMENTING PESSIMISTIC or OPTIMISTIC CONCURRENCY.

"please advise.."
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12260319
oops! sorry, that last posting I made at 9:07AM.. that was for a different question! hahaa DOH!
0
 

Author Comment

by:syska
ID: 12260636
gahhh, really that simple :-)

I had the question asked on microsoft news group and a other danish forum, no answer there for 2 days, and then u answer it in like NO TIME

Amazing :-P

A few more things:

how do I remove that + sign, to the left, where the relation name becomes visable, when I click at it?

How do I set the Column width? I can find to set the default width but not for each column?

think that will be all for now
0
 
LVL 8

Accepted Solution

by:
gregasm earned 125 total points
ID: 12260887
Would you mind opening another question for the follow up questions you asked above? Thanks. =]]
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:syska
ID: 12260991
Will consider it, since I aint got so many points
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12261553
How come you gave the answer a C grade?
0
 

Author Comment

by:syska
ID: 12263429
hmm, sorry :-/

Took the wrong one, It should have been A, but I must have taken the wrong one.

The solution was the first comment.

But just a little irritated that he would not answer the 2 other questions, that I had to his solution, but it he wont, I can't make him :-(

Will just have to wait until I get some more points :-P

thanks
0
 
LVL 8

Expert Comment

by:gregasm
ID: 12263611
I'll be happy to answer your other questions, but please try to look at this from our point of view. The individual questions (with the clear start and the clear end) are our incentive to reply and offer help. Without the incentive, then you'd have a newgroup, or a forum, and the questions would not be answered for a few days.

The points are an incentive for us to answer the questions quickly and completely as well. Otherwise, this would be no different than a newgroup or a forum, where the questions may not be answered for a while.

Thanks for your consideration =]]
0
 

Author Comment

by:syska
ID: 12263923
yahh, but still its very related questions to my question, its not like its about something completely different :-P
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now