AshishKukreja

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




Re: Windows Forms General Windows Form Problem

vinoth kumar.R

Hai

This is possible u said u maintain 2 dataset then fill the second dataset query with parameter

pass the pass the parameter for the second dataset in the second dataset write the following query

Select Sal_id, Salary from salarytbl where empid = '" + empcode"'

pass the parameter value for empcode.






Re: Windows Forms General Windows Form Problem

AshishKukreja

but I want that empcode automatically show as per employee table

means which id shown in Employee table automatically salary table take this value

reply please






Re: Windows Forms General Windows Form Problem

vinoth kumar.R

no prob also select empid from the table






Re: Windows Forms General Windows Form Problem

Gavin Jin - MSFT

Hi, first I will check my understanding with you, if there is any misunderstanding, please feel free to let me know.

You want to show related data from another dataset synchronically, isn’t it

I think you can use BindingSource to create a master-detail relation with these two datatables.

Here is a sample ,hope it helps

Imports System.Data

Imports System.data.SqlClient

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn As New SqlConnection("Server=(Local);" & _

"DataBase=Northwind; Integrated Security=SSPI")

Dim sqlstr As String = "SELECT * FROM Employees"

Dim ds As New DataSet

Dim dt1 As New DataTable

Dim dt2 As New DataTable

ds.Tables.Add(dt1)

ds.Tables.Add(dt2)

Dim da1 As New SqlClient.SqlDataAdapter _

("Select * from Orders", conn)

Dim da2 As New SqlClient.SqlDataAdapter _

("Select * from [Order Details]", conn)

da1.FillSchema(dt1, SchemaType.Mapped)

da2.FillSchema(dt2, SchemaType.Mapped)

Dim rel As New DataRelation("FKOrders_Detail_Orders", _

ds.Tables(0).Columns("OrderID"), _

ds.Tables(1).Columns("OrderID"))

ds.Relations.Add(rel)

Dim bsOrders As New BindingSource

bsOrders.DataMember = ds.Tables(0).TableName

bsOrders.DataSource = ds

DataGridView1.DataSource = bsOrders

Dim bsOrderDetails As New BindingSource

bsOrderDetails.DataSource = bsOrders

bsOrderDetails.DataMember = "FKOrders_Detail_Orders"

DataGridView2.DataSource = bsOrderDetails

da1.Fill(dt1)

da2.Fill(dt2)

End Sub

End Class

Gavin






Re: Windows Forms General Windows Form Problem

AshishKukreja

sir

I am working in C# not in Visual Basic

can you explain it in C#
Thanks






Re: Windows Forms General Windows Form Problem

Gavin Jin - MSFT

Hi, you can follow this article .There is a C# code example creates a master/detail form using two DataGridView controls bound to two BindingSource components. Hope it helps.

http://msdn2.microsoft.com/en-us/library/c12c1kx4.aspx

Best Regards

Gavin