Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

insert dataset as temp table in SQL

Posted on 2004-10-14
7
Medium Priority
?
430 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:Fred Goodwin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12311569
0
 
LVL 7

Author Comment

by:Fred Goodwin
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Author Comment

by:Fred Goodwin
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 2000 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

Industry Leaders: 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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

730 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