Solved

Show results from multiple DataTable in one DataGridView

Posted on 2007-04-04
2
3,320 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 50 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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