stored procedure + dataset

  • Thread starter Thread starter Alejandro Becker
  • Start date Start date
A

Alejandro Becker

Hi.
I want to execute a stored procedure. I am using sql server 2000 and vb.net.
I need to retrieve the data in a dataset, not in a DataReader.

how can I do?

Thanks.
 
There's not any difference other than setting the CommandType to
StoredProcedure.

Dim da as New SqlDataAdapter
Dim cn as New sqlConnectionString(SomeConnectString)

Dim ds as New DataSet
Dim cmd as New SqlCommand("usp_Whatever", cn)
cmd.CommandType = StoredProcedure
da.SelectCommand = cmd

da.Fill(ds,"SomeTableName")

This is a very simplified version, but there's not much difference other
than da.Fill instead of ExecuteReader.

Also, if you do this, you'll need to set your own Update Logic or have the
DataAdapter Configuration wizard do it for you b/c commandbuilders infer the
other commands from the select command.

Check out this link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadonet/html/commandbuilder.asp

HTh,,

Bill
 
I have several examples in my article in MSDN online:
http://www.betav.com/msdn_magazine.htm

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
You will need to create a SqlCommand type, set it's CommandText to the sproc
name, it's type to StoredProcedure and then add the necessary
Input\Output\ReturnVaue parameters. Some folks would are you should code up
the CommandText yourself like:

CALL mySPROC ?,?,?

However, the param types does a very nice job of doing this for you.
 
No one I know recommends this approach.

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top