C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ADO.NET »

Relationship in DATAgrid.


Posted Date: 07 Aug 2009    Resource Type: Code Snippets    Category: ADO.NET
Author: NeetuMember Level: Diamond    
Rating: 1 out of 5Points: 10



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

Attachments

  • Relationship in grids. (31157-7431-relationshipingrids.rar)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Relationship in Datagridview  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Using DataReader
    Previous Resource: Program for the beginners in ADO.Net.
    Return to Discussion Resource Index
    Post New Resource
    Category: ADO.NET


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use