?
Solved

tableadapter data to another table

Posted on 2009-12-27
6
Medium Priority
?
630 Views
Last Modified: 2013-11-26
VS2005
VB.NET
I'm looking for the best practice way to take a table adapter (method) rows and insert those rows into another table.  I created a query in a table adapter (GetDoGrouping) and I want to in code get those rows and insert them into another table (I have a ODBC connection set for another table).
TableAdapter: DOAdapter
Method: GetDoGrouping
0
Comment
Question by:wayneburr
  • 4
  • 2
6 Comments
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26129497
Hi wayneburr, Can u post your code??
0
 

Author Comment

by:wayneburr
ID: 26129540
The idea is to get the rows from the TableAdapter into another datatable so I can loop thru is row to do some processing.  This is what I started out with and backed out the other processing because I was having problems.

Dim dt As New DataTable()
 
Me.RevenueTableAdapter1.Fill_DO_Grouping(dt)
For Each row As DataRow In dt.Rows
''Processing of the row
Next
0
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26129575
Please post Fill_DO_Grouping() method also.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

Author Comment

by:wayneburr
ID: 26129619
This is the Fill_DO_Grouping:

SELECT     NETWORK, BROADCASTMONTH,
SUM(PROJECTEDGROSS-( PROJECTEDREPDISCOUNT+ PROJECTEDOTHERDISCOUNT + ACTUALGROSS) ) AS TotalNet,
CASE WHEN sum(PROJECTEDAGENCYDISCOUNT) = 0 THEN 0 ELSE sum(PROJECTEDAGENCYDISCOUNT) END as AGENCYNET,
CASE WHEN sum(PROJECTEDREPDISCOUNT) = 0 THEN 0 ELSE sum(PROJECTEDREPDISCOUNT) END as REPNET,
                       COUNT(NETWORK) AS cntNetwork, AEINITIALS
FROM         EDA4010.REVENUE
GROUP BY AEINITIALS, BROADCASTMONTH, NETWORK
ORDER BY AEINITIALS, BROADCASTMONTH, NETWORK
0
 
LVL 11

Accepted Solution

by:
ROMA CHAUHAN earned 2000 total points
ID: 26129624
   'Create connection to your database
        Dim cn As New OdbcConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath("/app_data/AccountInfo_Nov14_2009.mdb"))
        'take the dataAdapter to fetch the data
        Dim adpt As New OdbcDataAdapter("SELECT NETWORK, BROADCASTMONTH,SUM(PROJECTEDGROSS-( PROJECTEDREPDISCOUNT+ PROJECTEDOTHERDISCOUNT + ACTUALGROSS) ) AS TotalNet,CASE WHEN sum(PROJECTEDAGENCYDISCOUNT) = 0 THEN 0 ELSE sum(PROJECTEDAGENCYDISCOUNT) END as AGENCYNET,CASE WHEN sum(PROJECTEDREPDISCOUNT) = 0 THEN 0 ELSE sum(PROJECTEDREPDISCOUNT) END as REPNET,COUNT(NETWORK) AS cntNetwork, AEINITIALS FROM(EDA4010.REVENUE) GROUP BY AEINITIALS, BROADCASTMONTH, NETWORK ORDER BY AEINITIALS, BROADCASTMONTH, NETWORK", cn)
        'Define datatable
        Dim dtSource As New DataTable("dtAceData")
        'Take data in datatable
        adpt.Fill(dtSource)
        adpt.Dispose()
        'Define Destination table
        Dim dtDestination As New DataTable()
        dtDestination = dtSource.Clone
        'Loop for all the rows in Source table
        For Each row As DataRow In dtSource.Rows
            ''Processing of the row
            dtDestination.ImportRow(row)
        Next
0
 
LVL 11

Expert Comment

by:ROMA CHAUHAN
ID: 26129625
'To copy the whole first table data in destination table then you can do
        Dim dtDestination As New DataTable()
        dtDestination = dtSource.Copy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

862 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