[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Copy datatable into new datatable and rename columns

Posted on 2011-09-21
3
Medium Priority
?
445 Views
Last Modified: 2012-05-12
I have a datatable with the following columns

[start Date]
[Pmt Amount]
[Compounding]

How do I copy 2 of those columns into a new datatable to pass to SQL 2008 as a structured data table

the new datatable would be
startDate
PaymentAmt
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
x77 earned 2000 total points
ID: 36575647
I think you don' t need create other table.
You can Map columns from your table to Parameters on Command that update Sql 2008.

Note that it is very easy copy to other table, but I need know:

   Copy only current values ?
   Copy Deleted Rows ?

Note that if you use DataAdapter Update you need copy rowstate and also original an current values.

To do this

   dim ccOr = new dataColumn(){ OrignalTabl.Column("start Date"), OrignalTabl.Column("Pmt Amount"),
   Dim ccDes = new dataColumn(){ OrignalTabl.Column("startDate"), OrignalTabl.Column("PaymentAmt "),

   For each Row as Datarow in OriginaTable
      dirm rDes = DestTable.newRow
      for n=0 to ccor.length -1
         rdest(ccdes(n)) = row(ccor, DataRowVersion.Original)
      next
      rdes.rows.add(rdest)
   next

   Tdest.acceptchanges

Now, write code to delete deleted rows and Update modified rows

   for i as integer = 0 to OriginaTable.rows.count -1
       select case OriginaTable.rows(i).rowstate
            Case DataRowState.Modified
                   dim row=  OriginaTable.rows(i), rdest=DestTable.rows(i)
                   for n=0 to ccor.length -1
                        rdest(ccdes(n)) = row(ccor)
                   next
            Case DataRowState.Deleted
                destTable.rows(N).delete
       end select
   next
0
 
LVL 15

Expert Comment

by:x77
ID: 36575663
Note. I write code directly, I don´t verify.

by sample :  where says         row(ccor)    ->    row(ccor(n))

0
 

Author Closing Comment

by:lrbrister
ID: 36576045
You put me on the right track...thanks

Dim dt As New DataTable
dt = ConvertTo(l_lead.Payments)
dt.Columns(0).ColumnName = "LeadType"
blah...blah...blah..

dt.Columns.Remove("LeadType")
dt.Columns.Remove("PaymentStreamID")
blah...blah...blah..

dt.Columns("EventType").SetOrdinal(0)
dt.Columns("StartDate").SetOrdinal(1)
dt.Columns("PmtAmount").SetOrdinal(2)
blah...blah...blah.."
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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