Solved

Show results from multiple DataTable in one DataGridView

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

627 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