Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 1st, 2005, 01:37 PM
Authorized User
Join Date: Jun 2003
Location: Irvine, CA, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default Store Results From DataReader


I want to create a Function that returns the result of a parameter Stored Procedure in a DataTable if that's possible. I've tried a couple of things with no success. The reason I need to do this is I have to close the SQL connection before exiting the Function. If I do this, my returned recordset disappears.

Here's my code to get the recordset using SQLCommand:

Public Function GetRecordSet() as New DataTable
Dim sConnString As String = "Data Source=" & SqlServerName & "; User ID=" & SqlLogin & "; Password=" & SqlPWD & "; Initial Catalog=" & mcWebPPO
Dim oConn As New SqlConnection(sConnString)
Dim oComm As New SqlCommand("MySP", oConn)
oComm.CommandType = CommandType.StoredProcedure

'*** Allow for SP's Return Value
Dim oParm As SqlParameter = oComm.Parameters.Add(mcReturnValue, SqlDbType.Int)
oParm.Direction = ParameterDirection.ReturnValue

'*** Setup the input parameter
oParm = oComm.Parameters.Add("@SubjectSearch", SqlDbType.VarChar, 50)
oParm.Value = "What my parameter is"

Dim oDR As SqlDataReader = oComm.ExecuteReader

Do While oDR.Read()
   Console.WriteLine("{0}, {1}", oDR.GetName(0), oDR.GetName(1))
   Console.WriteLine("{0}, {1}", oDR.GetValue(0), oDR.GetValue(1))

GetRecordSet = ?????
Return GetRecordSet


Console.WriteLine(mcReturnValue & ": {0}", oComm.Parameters(mcReturnValue).Value)

End Function


Reply With Quote
  #2 (permalink)  
Old February 2nd, 2005, 12:59 AM
Friend of Wrox
Join Date: Oct 2003
Location: Chennai, TamilNadu, India.
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi

Set the return Parameter Value to variable and return that variable.It wont disappear.If you want to set those values in DataTable .Create an dataset and add those two return values in the DataTable and return the dataset.
Reply With Quote
  #3 (permalink)  
Old February 2nd, 2005, 11:18 AM
Authorized User
Join Date: Jun 2003
Location: Irvine, CA, USA.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks Santhi for the suggestion, I never thought of using a Variable.
I figured out a way to use the SQLCommand and SQLDataAdapter to run a Stored Procedure that returns the results in a DataTable. That works for me.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
datareader MunishBhatia ASP.NET 2.0 Professional 2 October 17th, 2007 07:05 AM
Edit Query Results in Results Grid druid2112 SQL Server 2005 1 June 28th, 2007 08:49 AM
Datareader NitinJoshi ADO.NET 4 January 31st, 2005 08:34 AM
DataReader cjcd BOOK: Beginning ASP.NET 1.0 2 March 21st, 2004 01:06 PM
How to store results of several scripts in table fawadr4656abp Oracle 0 June 13th, 2003 03:00 AM

All times are GMT -4. The time now is 01:53 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.