danorme
asked on
Add Multiple Rows to a DataSet / DataTable
Hellow everyone. I am running into a slight problem and cant seem to figure it out.
I am pulling Data from one table:
<<Code>>
sqldaSelectCond.SelectComm and.Parame ters("@prg m").Value = varLoanProgram
DsSelectConditions1.tbl_li st_conditi ons.Clear( )
sqldaSelectCond.Fill(DsSel ectConditi ons1.tbl_l ist_condit ions)
<<End Code>>
This will pull over about 10 to 15 records and fill the DsSelectConditions DataSet.
I then need to add those 10 or so records to the other Dataset(DsConditions)
How can I do this.
Here is my code for adding 1 record.
<<Code>>
drConditions = dsTeamplateDB1.tblConditio ns.NewRow( )
drConditions.Item("PID") = varPID
drConditions.Item("LoanID" ) = varLoanID
drConditions.Item("conditi on") = varCondition
dsTeamplateDB1.tblConditio ns.Rows.Ad d(drCondit ions)
<<End Code>>
Your help will be greatly appreciated.
I am pulling Data from one table:
<<Code>>
sqldaSelectCond.SelectComm
DsSelectConditions1.tbl_li
sqldaSelectCond.Fill(DsSel
<<End Code>>
This will pull over about 10 to 15 records and fill the DsSelectConditions DataSet.
I then need to add those 10 or so records to the other Dataset(DsConditions)
How can I do this.
Here is my code for adding 1 record.
<<Code>>
drConditions = dsTeamplateDB1.tblConditio
drConditions.Item("PID") = varPID
drConditions.Item("LoanID"
drConditions.Item("conditi
dsTeamplateDB1.tblConditio
<<End Code>>
Your help will be greatly appreciated.
ASKER
My bad. I need to also include two variables for each of those entries. varPID and varLoanID.
Kind of like this.
drConditions.Item("PID") = varPID
drConditions.Item("LoanID" ) = varLoanID
Where do I put this in the code that was so graciously provided.
Kind of like this.
drConditions.Item("PID") = varPID
drConditions.Item("LoanID"
Where do I put this in the code that was so graciously provided.
As I said "I'm not sure I've got the full picture" ;-)
Are we talking about - in the terms I used - the SourceDataTable or the DestinationDataTable? That is, do you want to put those variables in the record before you copy it from one table to the other, so that then both the original and the copied record will have those values in them? Or do you want to put those variables in the record after you copy it from one table to the other, so that then only one of the versions - the original or the copied record - will have them in it? And if it is the latter, do you wish to put them in the original or in the copy?
Roger
PS I'm just off out for the evening, but will come back to you ASAP after your response when I return.
Are we talking about - in the terms I used - the SourceDataTable or the DestinationDataTable? That is, do you want to put those variables in the record before you copy it from one table to the other, so that then both the original and the copied record will have those values in them? Or do you want to put those variables in the record after you copy it from one table to the other, so that then only one of the versions - the original or the copied record - will have them in it? And if it is the latter, do you wish to put them in the original or in the copy?
Roger
PS I'm just off out for the evening, but will come back to you ASAP after your response when I return.
ASKER
I need to add those variables to the copied records only.
I really do appreciate your help.
I really do appreciate your help.
ASKER
Ya know. There is one more part to this. The two tables are not exactly alike.
So, I guess this is what I need to do.
Take the original data
Map each of its fields to the fields of the new (destination) table.
So, I guess this is what I need to do.
Take the original data
Map each of its fields to the fields of the new (destination) table.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
varPID and varLoanID are the same for the copied records.
Got it. Awsome! I started VB 8 months ago and with the help of all you guys, my boss, and several books I have been able to make one heck of a program for my company. Thanks.
Got it. Awsome! I started VB 8 months ago and with the help of all you guys, my boss, and several books I have been able to make one heck of a program for my company. Thanks.
I'll also assume that the SourceDataTable and the DestinationDataTable have identical structures - number of columns and datatypes.
On that basis the code should be
For Each dr as DataRow In SourceDataTable.Rows
Dim newdr As DataRow = DestinationDataTable.NewRo
newdr.ItemArray = dr.ItemArray
DestinationDataTable.Rows.
Next
Roger