Solved

Show results from multiple DataTable in one DataGridView

Posted on 2007-04-04
2
3,282 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
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
kosturdur earned 50 total points
Comment Utility
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
Comment Utility
Sorry all DataSet2's must be DataSet1.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now