Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2007, 01:51 AM
Registered User
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Windows Form Problem

Sir

I have two Dataset naming Employee and Salary

Employee Dataset have three colomns coloumns ------------- Emp_id, Name, Address,

Salary Dataset have three more coloumns -------------------- Sal_id, Salary, Emp_id

in Employee Dataset Emp_id is parimary Key

in Salary Dataset Emp_id is Foreign Key


Now I want that both the dataset in Windows Form Employee Dataset in Details

and Salary Dataset in DatagridView.

that all things I done


Now what I required is when I select a Emp_id is 1
then in Datagridview they also show a detail of Emp_id is 1

I thing I clear my point.

and when you have any difficulty understanding this

please asked me

Please help me out in this

Thanks
Ashish

 
Old October 6th, 2007, 04:15 PM
Authorized User
 
Join Date: Dec 2004
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to DZukiewicz
Default

I think I understand

Employee DataSet
=======

- Emp_id PRIMARY KEY
- Name
- Address

Salary dataset
=============

- Sal_id
- Salary
- Emp_id FOREIGN KEY

You want to select all of the salary rows, where the emp_id = 1?

Firstly, you have to place the 2 DataTables into the same DataSet, and then add a DataRelation to the columns like this:

DataSet myDataSet = new DataSet();
myDataSet.Tables.Add ( GetEmployeeTable() );
myDataSet.Tables.Add ( GetSalaryTable() );

DataColumn prmyEmployeeId = myDataSet.Tables["Employee"].Columns["Emp_id"];
DataColumn frgnEmployeeId = myDataSet.Tables["Salary"].Columns["Emp_id"];

DataRelation dr = new DataRelation( prmyEmployeeId, frgnEmployeeId );

myDataSet.Relations.Add ( dr );

//Now get the row you need.

DataRow[] filteredRow = myDataSet.Tables["Employee"].Select("Emp_id = 1");

DataRow[] salaryRow = filteredRow[0].GetChildRows();

//Since there is a 1=>1 relation, salaryRow is of length 1.

Hope this helps

Dom





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch.14 Creating Windows Form User Controls problem SAIFI BOOK: Beginning Microsoft Visual Basic 2008 ISBN: 978-0-470-19134-7 1 September 29th, 2008 05:51 AM
repalcing windows form Medes C# 0 May 27th, 2006 04:03 PM
Windows Form rwalker General .NET 1 February 11th, 2005 01:44 AM
Windows Form Threading Problem nugie73 VB.NET 0 August 25th, 2004 06:12 AM
DataGrid(Windows Form) shiju VS.NET 2002/2003 1 November 1st, 2003 11:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.