The Following code will demonstrate that whenever user selects the dept from one grid he will get all the related employees in another grid.
Imports System.Data.OleDb Public Class Form2 Dim con As New OleDbConnection Dim da1 As New OleDbDataAdapter Dim da2 As New OleDbDataAdapter 'BindingSource:- The BindingSource component serves many purposes. First, it simplifies binding controls on a form to data by providing currency management, change notification, and other services between Windows Forms controls and data sources. This is accomplished by attaching the BindingSource component to your data source using the DataSource property. Dim emp As New BindingSource Dim deptm As New BindingSource
'DataSet:- The DataSet, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects. You can also enforce data integrity in the DataSet by using the UniqueConstraint and ForeignKeyConstraint objects
Dim data As New DataSet 'Dim dt As New DataTable
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Neet Full Data\NEETU (F)\VBNet\Dealing with grid\test.mdb;Persist Security Info=False" da1 = New OleDbDataAdapter("select * from emp", con) da2 = New OleDbDataAdapter("select * from dept", con) da1.Fill(data, "emp") da2.Fill(data, "dept") Dim dr As New DataRelation("demp", data.Tables("dept").Columns("deptno"), data.Tables("emp").Columns("deptno")) data.Relations.Add(dr) deptm.DataSource = data deptm.DataMember = "dept"
emp.DataSource = deptm emp.DataMember = "demp"
DataGridView1.DataSource = deptm DataGridView2.DataSource = emp
'da1.Fill(dt) 'emp.DataSource = dt 'DataGridView1.DataSource = emp
End Sub End Class
Regards Neetu
AttachmentsRelationship in grids. (31157-7431-relationshipingrids.rar)
|
No responses found. Be the first to respond and make money from revenue sharing program.
|