Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Show results from multiple DataTable in one DataGridView

Posted on 2007-04-04
2
Medium Priority
?
3,341 Views
Last Modified: 2012-05-05
I have a typed DataSet that contains two tables, related through key:
Table: People
ID FirstName LastName CompanyID

Table: Companies
ID Name

Key: People.ID -> Companies.ID

Note: DataSet is loaded from XML file, i.e. there is no database.

Problem:
I want to show data table (using DataGridView) with following columns:
First Name | Last Name | Company Name

What are my options?
Should I have a database, I could run an SQL query and show the results, but I don't have a database.
0
Comment
Question by:rgavrilov
[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
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
kosturdur earned 100 total points
ID: 18855316
I also want to learn your questions answer. While I'm waiting for experts to answer your question, I found some information and want to share with you. There must be easier ways but;

1) You could loop two tables and build a new datatable. And use it.
2) You can create relation between the tables like;

 CompaniesDS.Relations.Add("myRelation",
    CompaniesDS.Tables["People"].Columns["CompanyID"],       // column in parent table
    CompaniesDS.Tables["Companies"].Columns["ID"]);      // column in child tablle

.....or

DataColumn primarykey = dataset.Tables["People"].Columns["CompanyID"];
DataColumn foreignkey = dataset.Tables["Companies"].Columns["ID"];
DataRelation myRelation = dataset.Relations.Add(primarykey, foreignkey);

.............you could use ListView Control and do something like;

DataSet1TableAdapters.PeopleTableAdapter peopleAdapter =
    new DataSet2TableAdapters.PeopleTableAdapter();
DataSet1.PeopleDataTable peopleDataTable;
peopleDataTable = peopleAdapter.GetData();
myListView.Items.Clear();
for (int i = 0; i < peopleDataTable.Rows.Count; i++)
{
  DataRow drow = peopleDataTable.Rows[i];
  ListViewItem lvi = new ListViewItem(drow["First_Name"].ToString());
  lvi.SubItems.Add(drow["Last_Name"].ToString());
   lvi.SubItems.Add(DataSet2.Relations["myRelation"].ChildColumns["Company_Name"].ToString());
   myListView.Items.Add(lvi);
}
Kosturdur
0
 
LVL 5

Expert Comment

by:kosturdur
ID: 18855405
Sorry all DataSet2's must be DataSet1.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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