473,395 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

dynamic creation of datasets from stored sql server procs

How would I create a dataset dynamicly on the fly.. I looked at the example
in the MSDN article on datasets but it wouldn't work (the northwind example)

here's what i want to do...
I want to execute the stored procedure "SP_GETNAMES" on SQL server and have
it return the table, which could change over time as more return columns get
added of course, so instead of makeing a fixed data set as you would when
you generate one with the data adapter, i want to create one dynamicly...
any examples on how i would do that with that stored procedure name? thanks!
Nov 20 '05 #1
1 970
Hi Brian,

I'm not sure I'm following what you're after, but there is a fairly simple
way to create an sp dynamically, and thus you can run anything dynamically.
Here's how (I explain at the bottom):
ocmd = New SqlCommand("exec sp_dropsp_copyintomagt", oconnx)

Try

ocmd.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

creationstring = "CREATE PROCEDURE sp_copyintomagt AS " _

& "if exists (select * from information_schema.tables where table_name = " _

& Chr(39) & magtfilename & Chr(39) & ")" & vbCrLf & "drop table " _

& magtfilename & vbCrLf _

& "select * into imc_extra.." & magtfilename & " from imc..hvimport" _

& vbCrLf & "go"

Dim sqladaptx As New SqlDataAdapter

' create a non-table designating sqldataadapter for these non-queries

sqladaptx.SelectCommand = New SqlCommand(creationstring, oconnx)

Try

sqladaptx.SelectCommand.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

ocmd = New SqlCommand("exec sp_copyintomagt", oconnx)

Try

ocmd.ExecuteNonQuery()

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try

First I delete the sp. Then I create the sp using executenonquery. Finally
I execute the new sp, which was created dynamically.

Let me know if you have any questions about this approach.

HTH,

Bernie Yaeger

"Brian Henry" <br******@adelphia.net> wrote in message
news:er**************@TK2MSFTNGP11.phx.gbl...
How would I create a dataset dynamicly on the fly.. I looked at the example in the MSDN article on datasets but it wouldn't work (the northwind example)
here's what i want to do...
I want to execute the stored procedure "SP_GETNAMES" on SQL server and have it return the table, which could change over time as more return columns get added of course, so instead of makeing a fixed data set as you would when
you generate one with the data adapter, i want to create one dynamicly...
any examples on how i would do that with that stored procedure name? thanks!

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
6
by: MattC | last post by:
Hi, I'm implementing a new Business Layer in one of our applications. I'm toying with the idea of placing all the Create, Read, Update and Delete SQL in the object in question and build a...
7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
5
by: Ronald S. Cook | last post by:
I've read a few posts on the stored procedure vs dynamic sql debate. I ran a few performance test for myself and it appears to be a wash. Given that, I'm leaning toward dynamic sql mostly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.