Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

2 DataGrids(parent/child) of a Relationel tables

Posted on 2004-10-08
12
384 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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