Inserting records into table from previous query results

Posted on 2007-08-02
Last Modified: 2013-11-26
Hi Experts:
Im trying to write some code that will take the results of a query and use those results to insert them into a new table in SQL05, not to sure how to accomplish this. Do I need a SQLAdapter? Do I need to save the results of the query into a dataset and use the dataset to populate the table?
Any help or ideas will be of great help. Im new to so some code example will be of great help.
This is the part of the code that I have so far:

Dim SQL3 As String = "SELECT FIL1, FIL2,FIL3,FIL4 FROM activitydetail where activity_id > " & CStr(minActivityID) & " and activity_id <= " & CStr(maxActivityID) & " and customer_id = 1"
' Create command object
Dim cmd3 As New OdbcCommand(SQL3)
cmd3.Connection = TVconn
' Call command's ExecuteReader
Dim reader3 As OdbcDataReader = cmd3.ExecuteReader()

&&&Next I will like to take those results which are about 7,000 rows and insert them into a new table in SQL05.

Question by:Oneill0003
    LVL 96

    Accepted Solution

    If you have 2005, then I would use an OdbcDataAdapter, and call the Fill method to get a DataTable, and then use the SqlBulkCopy class to write the DataTable to SQL Server.


    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now