Windows Develop Bookmark and Share   
 index > Windows Forms General > dynamic datatable
 

dynamic datatable

We have 2 datatables both with a FileNumber column.

First Table: 

Continuence:

FileNumber | ContinuedDate

Second Table: 

FileNumber | OriginalSaleDate


There can be many ContinuedDates corresponding to the FileNumber in the Continuence table. 

ex:
FileNumberContinuedDate
12301/02/03
12302/03/04
12303/04/05
23412/15/02

There can be only one FileNumber in the OriginalSaleDate table. 

ex:
FileNumberOriginalSaleDate
12312/15/02
23412/18/04
34512/15/02
...etc (no more then 1 FileNumber per OriginalSaleDate)

How do we query and create one table with one OriginalSaleDate per FileNumber but many ContinuedDates per FileNUmber?

We need to query by OriginalSaleDate and ContinuedDate. The user must search by a date. Either ContinuedDate or OriginalSaleDate. If either column has the value entered its row is returned. Basically, we need to search for one date in both tables and return one table with OriginalSaleDate, ContinuedDate and the FileNumber. 

ex: (user searches for 12/15/02) The following table would be returned:

FileNumberOriginalSaleDateContinuedDate
12312/15/0201/02/03
12312/15/0202/03/04
12312/15/0203/04/05
23412/18/0412/15/02
34512/15/02


We have to have 2 separate tables in our database. We're looking to create a dynamic datatable with the above data, then populate a datagrid/crystal report.
MigrationUser 1  Wednesday, April 20, 2005 10:41 PM
It sounds like you just need to define a simple relationship between the two tables and then filter the datagridview for the appropriate records.

The basic steps would be to:

   1.  Create a DataAdapter for each table

   2.  Generate a DataSet

   3.  Add a DataView to the project

   4.  Fill the DataSet from each DataAdapter

   5.  Add a relationship to the DataSet
        ie:  DataSet1.Relations.Add("RelationshipName", DataSet1.ParentTableObj.Columns("ParentKeyCol"), DataSet1.ChildTableObj.Columns("ChildKeyCol"))

   6.  Set the DataView Table property to the child table
        ie:  DataView1.Table = DataSet1.Relations("RelationshipName").ChildTable

   7.  Set the DataGrid DataSource property to the DataView
        (leave the DataMember empty)

   8.  Set the DataView RowFilter property to display the appropriate records
        ie:  DataView1.RowFilter = "Parent(RelationshipName).OriginalSaleDate = #12/15/02# Or ContinuedDate = #12/15/02#"


You might want to read up on relational database design a bit.  The situation you've described is a classic example of the one-to-many relationship.

Hope that helps.  Good luck!
MigrationUser 1  Wednesday, April 20, 2005 11:57 PM

Hello,

Can you please post the basic steps for a many-to-many relationship? I assume it's not that simple as a simple relationship but I hope there is a way. I do understand relational databses and many-to-many relationships quite well but I'm new to datasets, datadapters and so on.

Thank you in advance,

Marcelo

MarceloRos  Wednesday, November 21, 2007 8:29 AM

You can use google to search for other answers

Custom Search

More Threads

• Disable RS232 serial mouse
• How create tool bar IE in C#
• Format / Input Mask on Datagrid column
• webbrowser document does not update or refresh after user action
• SplitContainer panel scroll bar.
• problem with adding a new item into ComboBox
• open chm from winform
• Getting Windows Media Player component to switch to a new movie
• How do I get an Excel range address when pasting/droping to a TextBox
• DataGridView tooltip InitialDelay value change...?