How to fill DataSet from stored procedure?

VB.NET

    Next

  • 1. Redirect Console I/O?
    Ok, I have my own console class that lets me allocate a console, free it, etc. in my windows vb .net application, hell it even hides the cursor, set colors, etc. But the one thing I want to do is redirect the standard console class text from the 'output' in the VS IDE to my console window during debug sessions, when not debugging, everything works fine... so how do I get VS IDE to use my window not 'output'? Thx.
  • 2. HTMLHelp Newbie ?
    I want to show a specific HTML Help topic when the user presses a button, but I can't find any documentation on how to call HTML Help from vb.net except using the HelpProvider component which is control-specific. Any suggestions? Thanks; Michael
  • 3. Cruel and unusual punishment
    Hi Herfried, That's a shame. As punishment I was going to order you to come to London and do all of <our> MacDonalds in one day. - "gebloaten zum Max". Regards, Fergus
  • 4. Serious discussion about removing controls dynamically
    Hi Jose, But it's a hell of a great planet!! I've seen your method before. It is very unambiguous and there are no worries about whether you are tripping over your own tail. First you collect. Then you remove. Simple. But, as I mentioned in my post above, screen space is very important, so, for me, it is too long. However, welcome to the debate. :-) Regards, Fergus
  • 5. Scrolling a ListBox
    How do I make a listbox scroll down as new items are added to it so that the last added item will always be visible?

How to fill DataSet from stored procedure?

Postby Nikolay Petrov » Thu, 26 Aug 2004 23:34:15 GMT

How to fill DataSet from stored procedure?



Re: How to fill DataSet from stored procedure?

Postby One Handed Man ( OHM - Terry Burns ) » Thu, 26 Aug 2004 23:49:28 GMT

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








Re: How to fill DataSet from stored procedure?

Postby Nikolay Petrov » Thu, 26 Aug 2004 23:55:13 GMT

I know this, but how actually to read the data returned by the stored
procedure and put it in the dataset?












Re: How to fill DataSet from stored procedure?

Postby Shiva » Thu, 26 Aug 2004 23:59:56 GMT

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 --





How to fill DataSet from stored procedure?




Re: How to fill DataSet from stored procedure?

Postby Jeff Johnson [MVP: VB] » Fri, 27 Aug 2004 00:03:21 GMT







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")



Re: How to fill DataSet from stored procedure?

Postby Matt S » Fri, 27 Aug 2004 00:10:55 GMT

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.











Re: How to fill DataSet from stored procedure?

Postby Nikolay Petrov » Fri, 27 Aug 2004 00:12:55 GMT

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?












Re: How to fill DataSet from stored procedure?

Postby Matt S » Fri, 27 Aug 2004 00:21:13 GMT

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.







select









Re: How to fill DataSet from stored procedure?

Postby Nikolay Petrov » Fri, 27 Aug 2004 00:37:01 GMT

Thank you all guys












Re: How to fill DataSet from stored procedure?

Postby Jeff Johnson [MVP: VB] » Fri, 27 Aug 2004 00:45:43 GMT






select

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?



Similar Threads:

1.fill dataset from Sql Server stored procedure?

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 was hoping to use a DataAdapter.  
But I think the data adapter only uses select statements. I could write the 
sp in my vb.net app, but the sp references UDF's I wrote in the Sql Sever.  I 
will guess that I will need to stick with the ADODB recordset object for 
this.  But I am open to any better suggestions on how to fill the 
datatable/dataset with the data from the stored procedure.

Thanks,
Rich

2.Fill strongly type dataset from stored procedure

Dear all,

I have a file-strongly type dataset, that have two independent table inside 
it.
I want to fill the two table in the dataset by one stored procedure(have two 
select sql on it) how can i do

e.g.
create spname
..
SELECT * FROM table1
SELECT * FROM table2
GO

and

Dataadapter.fill(dataset.table1)
but how about table2


3.Filling a muti-table typed dataset using a stored procedure

Hi,

I have a stored procedure that makes two separate SELECT.    I then create 
a typed dataset and drag the stored procedure to the designer which creates 
2 tables.... the first one by default has the name of the stored procedure 
and the second one has the name Table1.  I rename both tables to more 
significant names.

I am trying to fill the typed dataset with a call to the stored 
procedure.... however, calling Fill will actually create 2 additional 
tables on my dataset.  I have filled untyped datasets with multiple table 
stored procedures but I can't seem to be able to solve it for typed 
datasets.

Thanks,

Jeronimo

4.Problem filling Strongly Typed DataSet from an Oracle 9i stored procedure that returns multiple ref cursors

5.how to fill a dataset from a DB2 stored procedure

Hi all gurus,
I am using a DB2 stored procedure which selects some data from a table and
opens a cursor. I want to take this data in a Dataset... but when I use the
Dataadapter's fill method the dataset doesnot contain any data. How can I
fetch the data from the cursor to the Dataset?

thanks and regards,
Ashish Sheth


6. filling dataset with Sybase stored procedure

7. Fill typed dataset with one stored procedure call

8. Filling a dataset using one stored procedure



Return to VB.NET

 

Who is online

Users browsing this forum: No registered users and 44 guest