473,382 Members | 1,355 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,382 software developers and data experts.

How to fill DataSet from stored procedure?

How to fill DataSet from stored procedure?
Nov 21 '05 #1
9 47141
It goes a bit like this . . .

Dim cmd As New OleDb.OleDbCommand

cmd.CommandType = CommandType.StoredProcedure

cmd.CommandText = "MyStoredProcedure"

cmd.Connection = MyConnection
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?

Nov 21 '05 #2
I know this, but how actually to read the data returned by the stored
procedure and put it in the dataset?
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
It goes a bit like this . . .

Dim cmd As New OleDb.OleDbCommand

cmd.CommandType = CommandType.StoredProcedure

cmd.CommandText = "MyStoredProcedure"

cmd.Connection = MyConnection
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Nov 21 '05 #3
I assume you are using MS SQL Server.

-- Code Start --
Dim sqlCon As New SqlConnection (<connection string>)
Dim sqlAdp As New SqlDataAdapter
Dim sqlCmd As New SqlCommand
Dim ds As New DataSet

sqlCmd.Connection = sqlCon
sqlCmd.CommandText = <sp name>
sqlCmd.CommandType = CommandType.StoredProcedure
' Add any parameters to the stored proc here using sqlCmd.Parameters
collection
sqlAdp.SelectCommand = sqlCmd
sqlAdp.Fill (ds)
-- Code End --

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?

Nov 21 '05 #4

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Create a xxxCommand object around the stored procedure and then use that
object when creating the xxxDataAdapter.

Air code:

Dim cnn As SqlConnection = New SqlConnection("Data Source=MySrv;Initial
Catalog=MyDB;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand = New SqlCommand("MySP", cnn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet

da.Fill(ds, "MyTable")
Nov 21 '05 #5
Try this.....

' Open db connection

Dim cnn As New SqlConnection(CONNECTION_STRING)

cnn.Open()

' Set command for the stored procedure

Dim cmd As New SqlCommand

With cmd

..CommandType = CommandType.StoredProcedure

..Connection = cnn

..CommandText = "CustOrderHist"

..Parameters.Add("@CustomerID", "ALFKI")

End With

' Create data adapter

Dim da As New SqlDataAdapter(cmd)

' Fill dataset from adapter

Dim ds As New DataSet

da.Fill(ds)

Hope this helps.

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
It goes a bit like this . . .

Dim cmd As New OleDb.OleDbCommand

cmd.CommandType = CommandType.StoredProcedure

cmd.CommandText = "MyStoredProcedure"

cmd.Connection = MyConnection
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Nov 21 '05 #6
Maybe my question was wrong.
I needed to know does any data will be returned from stored procedure select
statment to dataset.
I mean when the sqlcommand.commandType is text and .CommandText is the SQL
statemen everything works ok, but when the same sql statment is in stored
procedure does the DataSet iss filled properly?
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:O4*************@TK2MSFTNGP12.phx.gbl...

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Create a xxxCommand object around the stored procedure and then use that
object when creating the xxxDataAdapter.

Air code:

Dim cnn As SqlConnection = New SqlConnection("Data Source=MySrv;Initial
Catalog=MyDB;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand = New SqlCommand("MySP", cnn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet

da.Fill(ds, "MyTable")

Nov 21 '05 #7
Whatever the stored procedure returns will be populated in the dataset -
exactly the same as if the commandType is Text and a SQL statement is
provided. Make sure the stored procedure you are using is returning what
you are expecting in query analyser or similar then use the code posted
previously - it should work.

Hope this helps.

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
Maybe my question was wrong.
I needed to know does any data will be returned from stored procedure select statment to dataset.
I mean when the sqlcommand.commandType is text and .CommandText is the SQL
statemen everything works ok, but when the same sql statment is in stored
procedure does the DataSet iss filled properly?
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:O4*************@TK2MSFTNGP12.phx.gbl...

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Create a xxxCommand object around the stored procedure and then use that
object when creating the xxxDataAdapter.

Air code:

Dim cnn As SqlConnection = New SqlConnection("Data Source=MySrv;Initial
Catalog=MyDB;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand = New SqlCommand("MySP", cnn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet

da.Fill(ds, "MyTable")


Nov 21 '05 #8
Thank you all guys
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:O4*************@TK2MSFTNGP12.phx.gbl...

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:eA**************@TK2MSFTNGP09.phx.gbl...
How to fill DataSet from stored procedure?


Create a xxxCommand object around the stored procedure and then use that
object when creating the xxxDataAdapter.

Air code:

Dim cnn As SqlConnection = New SqlConnection("Data Source=MySrv;Initial
Catalog=MyDB;Integrated Security=SSPI")
cnn.Open()
Dim cmd As SqlCommand = New SqlCommand("MySP", cnn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet

da.Fill(ds, "MyTable")

Nov 21 '05 #9

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
Maybe my question was wrong.
I needed to know does any data will be returned from stored procedure select statment to dataset.
I mean when the sqlcommand.commandType is text and .CommandText is the SQL
statemen everything works ok, but when the same sql statment is in stored
procedure does the DataSet iss filled properly?


Yes, IF the stored procedure returns a resultset. If it's a stored procedure
that only sends back a return value and/or fills output parameters then it
won't fill the DataSet, but then you wouldn't choose such a stored procedure
in the first place, would you?
Nov 21 '05 #10

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

Similar topics

2
by: Wayde | last post by:
Please help me if you know the answer to this. I want to create a dataAdapter, that fills a dataSet. However, I have a stored procedure that I want to use, that takes one int as input. I have been...
3
by: gh | last post by:
I have made the following stored procedure with the following select statement select * from user select * from order, orderdetail where order.id=orderdetail.id I know I can uses DataReader...
3
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, ...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
3
by: Viktor Popov | last post by:
Hi, I would like to ask you do you know how to return a resultset and int value from Stored Procedure. If we have a table Teachers ========= ID INT PK NAME VARCHAR(25) ADDR VARCHAR(75)
1
by: Telemaco | last post by:
Ho la necessitą di inserire i risultati di una stored procedure in un dataset. Mi spiego meglio .... Ho costruito una store procedure che incapsula una query di lettura su un database sqlserver...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
10
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I...
3
by: dawson | last post by:
Hello, from the code below, how do I add/send a parameter to the stored procedure? SqlConnection conn = null; conn = new...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.