Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 multiple records output

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-02 : 08:19:33
qaiser writes "how stored procedure returns multiple records in sql server 2005
and how front end handel it using vb.net."

dfiala
Posting Yak Master

116 Posts

Posted - 2006-05-02 : 11:01:27
A stored procedure will return the results of a select statement or statements.

SELECT * FROM ATable

Will return all the records from ATable.

If you have multiple select statements in a stored procedure it will return all the results.

Select * FROM ATable
Select * FROM BTable

will return two result sets.

To retrieve them in VB.NET, you have two basic choices...
1) Use a SqlDataReader (http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader(VS.80).aspx)
2) Use a SqlDataAdapter (http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter(VS.80).aspx)

The SqlDataReader lets you loop through the results one record at a time using the .Read method. If you have multiple result sets, you can use the .NextResult method to get to the next set of results.

The SqlDataAdapter puts all the results into a DataSet (http://msdn2.microsoft.com/en-us/library/system.data.dataset(VS.80).aspx), one DataTable http://msdn2.microsoft.com/en-us/library/system.data.datatable(VS.80).aspxfor each set of results.

The SqlDataAdapter is the easier way to get the data out unless you have all lot of data retrieve at one time or have to something else fancy.
Go to Top of Page
   

- Advertisement -