Retrieving 'Child' Rows

Posted on 2004-11-29
Last Modified: 2010-04-17
I have a database with a table (tblEmployees) that stores employees details. It is linked to a table called tblDocumentArchive that stores information about employee documents (ie contract, appraisals etc). The information stored are things like document title, create date etc. They are linked as a 1-many relationship by EmployeeNumber.

I have a .NET form that has an OleDbConnector, Adapters as necessary, and a Dataset (dsEmpDocs) that has both the above tables within it. I have created a datagrid (grdEmp) on my form that is populated with employee names at run time. (I use Me.adptEmployees.Fill(dsEmpDocs) to populate the list) All my other fields are populated with the employee details and as I moved through the list of employees, so the data changes in each field - as expected.

However, I have another datagrid (grdEmpDocs) that lists (or should anyway) each document that is 'attached' to the current employee, but when I move through my employees in grdEmp, my list of documents doesn't get refreshed (all the other data does)

How can I get my second grid to refresh with the first? I have been going around in circles trying everything programmatically with examples, or everything graphically with a few lines of code, and I think I have just confused myself as to where I am now.

Question by:Craig_Muckleston
    LVL 11

    Expert Comment

    when the user navigates you have to filter the rows for the second datatable and then bind it

            dsEmpDocs.Tables(0).DefaultView.RowFilter = "employeeid=" + selectedempid

    That should solve your problem.

    Have Fun!

    Author Comment

    Hi Pratap,

    Thanks for the info. I'm a little stuck though (I'm new to .NET). I understand everything you say up to "employeeid=" + selectdempid.

    Is this the same as saying
    dsEmpList.Tables(0).DefaultView.RowFilter = "EmployeeNumber" Is _ Me.tboEmpNo.Text

    What do I bind the DataGrid to then? (Sorry for sounding naive)
    LVL 11

    Accepted Solution

    no something like this

    dsEmpList.Tables(0).DefaultView.RowFilter = "EmployeeNumber="  + Me.tboEmpNo.Text

    that if your employeenumber is an integer or a number..

    dsEmpList.Tables(0).DefaultView.RowFilter = "EmployeeNumber='"  + Me.tboEmpNo.Text.Replace("'","''") + "'"

    the above if the emp# is a text (has alphabets in it)

    you dont have to bind it to the datagrid again. once its bound its good.. you are talking about a windows application right? and not there binding is slightly different

    Have Fun!

    Author Comment

    Hi Pratap,

    Thanks for all your help, it works a treat.


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    733 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

    20 Experts available now in Live!

    Get 1:1 Help Now