Have function return SqlDatReader and then read results. How?
- From: "D. Shane Fowlkes" <shanefowlkes@xxxxxxxxxxxxxxxxx>
- Date: Fri, 24 Mar 2006 10:32:01 -0500
Up until now, I've always had my functions return integers, strings, or
booleans. Now, I've (hopefully) written a function to return a 2 column,
single row datareader. Assuming I did this correctly (the function), how
could I look at the results of the function in page_load and get the values?
A little guidance would be great. Thanks once again!!
(using ASP/VB .NET 2 and VWD)
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim drAppData As SqlDataReader
Dim intDaysLeft As Integer
Dim strCloseDate As String
drAppData = DaysLeftInAppSeason(1)
intDaysLeft = drAppData("DaysLeft")
strCloseDate = drAppData("CloseDate")
....etc...
End Sub
*************************************************
Protected Function DaysLeftInAppSeason(ByVal intAppID As Integer) As
SqlDataReader
Dim objConnection As SqlConnection
Dim cmdSelect As SqlCommand
Dim drData As SqlDataReader
Dim strConnectString As String
Dim strSQL As String
strConnectString = yadda.....
strSQL = "SELECT CloseDate, DateDiff(Day, GetDate(), CloseDate) AS DaysLeft
FROM MyTable WHERE ID = " & intAppID
objConnection = New SqlConnection(strConnectString)
cmdSelect = New SqlCommand(strSQL, objConnection)
objConnection.Open()
drData = cmdSelect.ExecuteReader()
drData.Read()
objConnection.Close()
Return drData
End Function
.
- Follow-Ups:
- Re: Have function return SqlDatReader and then read results. How?
- From: sloan
- Re: Have function return SqlDatReader and then read results. How?
- From: Marina Levit [MVP]
- Re: Have function return SqlDatReader and then read results. How?
- Prev by Date: Re: Send Parameters to Stored Procedure
- Next by Date: Re: IDE/Debugger Extremely Slow
- Previous by thread: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
- Next by thread: Re: Have function return SqlDatReader and then read results. How?
- Index(es):
Relevant Pages
|