Solved

insert dataset as temp table in SQL

Posted on 2004-10-14
7
426 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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