Link to home
Start Free TrialLog in
Avatar of danorme
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.SelectCommand.Parameters("@prgm").Value = varLoanProgram
        DsSelectConditions1.tbl_list_conditions.Clear()
        sqldaSelectCond.Fill(DsSelectConditions1.tbl_list_conditions)
<<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.tblConditions.NewRow()
      drConditions.Item("PID") = varPID
      drConditions.Item("LoanID") = varLoanID
      drConditions.Item("condition") = varCondition
      dsTeamplateDB1.tblConditions.Rows.Add(drConditions)
<<End Code>>

Your help will be greatly appreciated.
Avatar of Sancler
Sancler

I'm not sure I've got the full picture.  You say you want to add records from one dataset - DsSelectConditions - to the other dataset - DsConditions.  But the code you show for adding new records refers to a third dataset - dsTeamplateDB1.  So I'll refer to SourceDataTable and DestinationDataTable and leave you to put the proper references in.

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.NewRow
      newdr.ItemArray = dr.ItemArray
      DestinationDataTable.Rows.Add(newdr)
   Next

Roger
Avatar of danorme

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.

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.
Avatar of danorme

ASKER

I need to add those variables to the copied records only.  

I really do appreciate your help.
Avatar of danorme

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.
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of danorme

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.