?
Solved

2 DataGrids(parent/child) of a Relationel tables

Posted on 2004-10-08
12
Medium Priority
?
388 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
[X]
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
  • 6
  • 4
12 Comments
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 375 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 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