Solved

insert dataset as temp table in SQL

Posted on 2004-10-14
7
421 Views
Last Modified: 2008-02-01
I have a dataset.  It could have 50 rows or 50,000 rows.  I want to create a temp table in SQL Server 2k that holds my data so that I can run a few stored procs on it and shoot out some summary data.  What I need to know is if there is a way to get the data from my dataset into a sql temptable.

Thanks
0
Comment
Question by:imsolost
  • 5
  • 2
7 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12311569
0
 
LVL 7

Author Comment

by:imsolost
ID: 12311700
Are saying that you would put the data into XML and then try to create the table with XML?  Can you give more more detail on what you are thinking?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12311777
well thats one way other wise just use maketable in sql to make the table and then update it with your dataset data.  Although it seems like a lot of wasted overhead to create this table each time.  Why not just create the table in your db and clear it each time before you add the new data?


0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 7

Author Comment

by:imsolost
ID: 12311917
ok if I create the table and clear it each time, how would I then go about getting the dataset into the table?
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
ID: 12311979
Public Function CreateCmdsAndUpdate(myDataSet As DataSet, myConnection As String, mySelectQuery As String, myTableName As String) As DataSet
    Dim myConn As New OleDbConnection(myConnection)
    Dim myDataAdapter As New OleDbDataAdapter()
    myDataAdapter.SelectCommand = New OleDbCommand(mySelectQuery, myConn)
    Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(MyDataAdapter)

    myConn.Open()

    Dim custDS As DataSet = New DataSet
    myDataAdapter.Fill(custDS)

    ' Code to modify data in DataSet here

    myDataAdapter.Update(custDS, myTableName)

    myConn.Close()

    Return custDS
End Function 'SelectOleDbSrvRows

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatacommondbdataadapterclassupdatetopic5.asp
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12312021
or use xml as previously suggested


IF you are using SQL Server

You can take the data in the dataset and write it to an XML string
http://msdn.microsoft.com/library/d...atasetasxml.asp

then pass that xml string to a stored procedure.
once you have the xml string you can use OPENXML to
insert your data

Ex

CREATE PROCEDURE spTest
@xmlData TEXT
AS
DECLARE
@xmlDocReturn INT

exec sp_xml_preparedocument @xmlDocReturn OUTPUT, @xmlData

INSERT INTO MyTable
(...)
SELECT
...
FROM OPENXML (@xmlDocReturn,'/ROOTTAG/ELEMENTTAG')
WITH (...)

exec sp_xml_removedocument @xmlDocReturn


for more documentation
http://msdn.microsoft.com/library/d..._oa-oz_5c89.asp
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12312066
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

16 Experts available now in Live!

Get 1:1 Help Now