Solved

insert dataset as temp table in SQL

Posted on 2004-10-14
7
424 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

21 Experts available now in Live!

Get 1:1 Help Now