Discussion Locked

How to map stored procedure to dataset

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a stored procedure which returns result for a query,i want to map this result to a dataset.
i could do this using sqldatareader,but my need is dataset,how shall i do this
can anybody could help me out on this

3 replies

by ncseric

Here are the steps:

1. Open a SqlConnection to your database.
2. Create a SqlCommand object and load it with the name and parameters (if any) for your stored proc. If you don't have parameters, you can just skip this step.
3. Create a SqlDataAdapter and use the SqlCommand object or SQL statement with it.
4. Create a DataSet object and fill it from the SqlDataAdapter.

Here's a code snippet in VB.NET...you'll have to supply the parameters for the SQL connection.

Dim cn As New SqlConnection
cn.ConnectionString = "server=myserver;database=mydb;uid=me;pwd=password;"
cn.Open()
Dim SQL as string = "SELECT * FROM tblData"
Dim da as New SqlDataAdapter(SQL, cn)
Dim ds As New DataSet()
da.Fill(ds)

This discussion is closed to new replies.