jdhackett
asked on
Create new Datatable from two linked datatables
Hi
I have two Datatables, dtRenewals and dtAgents. There is a field in each called AgentCode.
I'd like to create another table, dtRenewals_WithAgents, which would only contain the renewals that have an AgentCode that is in dtAgents.
How would I do this?
Thanks
I have two Datatables, dtRenewals and dtAgents. There is a field in each called AgentCode.
I'd like to create another table, dtRenewals_WithAgents, which would only contain the renewals that have an AgentCode that is in dtAgents.
How would I do this?
Thanks
You can loop through dtAgents, find associated rows from dtrenewals and add to a new datatable.
Have a look on the merging two datatable's logic in the below links
http://stackoverflow.com/questions/15967625/how-to-merge-two-datatables-which-having-different-schema
http://stackoverflow.com/questions/9107231/how-to-merge-two-datatable-containing-different-column-based-on-condition
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/f3ef1dfd-58db-4bd7-b3e1-91f06ed4382b
http://stackoverflow.com/questions/15967625/how-to-merge-two-datatables-which-having-different-schema
http://stackoverflow.com/questions/9107231/how-to-merge-two-datatable-containing-different-column-based-on-condition
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/f3ef1dfd-58db-4bd7-b3e1-91f06ed4382b
ASKER
@srosebabu - those links are for merging two different tables. I don't want to merge the tables, I just want the rows from dtRenewals where the Agent is in dtAgents.
can you provide some sample data for the both data-tables with the required merged data sample?
ASKER
Sample for dtRenewals:
PolicyRef = TEST09
AgentCode = ARC1
IssueDate = 31/04/13
PolicyRef = TEST10
AgentCode = ""
IssueDate = 31/04/13
PolicyRef = TEST11
AgentCode = BAR
IssueDate = 31/04/13
Sample for dtAgents:
AgentCode = ARC1
AgentName = Arch Insurances
AgentCode = ZAP
AgentName = Zap Insurances
In this example, I would only like the row for TEST09.
PolicyRef = TEST09
AgentCode = ARC1
IssueDate = 31/04/13
PolicyRef = TEST10
AgentCode = ""
IssueDate = 31/04/13
PolicyRef = TEST11
AgentCode = BAR
IssueDate = 31/04/13
Sample for dtAgents:
AgentCode = ARC1
AgentName = Arch Insurances
AgentCode = ZAP
AgentName = Zap Insurances
In this example, I would only like the row for TEST09.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Very neat, thanks.