you can't close ur connection/datareader until AFTER you've finished with
it. That's because datareaders are CONNECTED to the database. Of course,
it's a pain to open a connection/datareader in one function and then have to
remember to close it in another ...it's hard to maintain and likely to cause
bugs.
One solution is to use a datatable which is disconnected.
Another solution is to map your datareader into objects, and return that
instead.
so you might create something like (total pseudocode)
public class DaysList
field int daysLeft
field date closedDate
property DaysLeft
property ClosedDate
end class
....
objConnection.open()
dr.Read()
DaysList dl = new DaysList(dr("DaysLeft"), dr("CloseDate");
dr.close()
connection.close()
return dl
hopefully that gives you some ideas..
Karl
--
http://www.openmymind.net/ http://www.fuelindustries.com/
"D. Shane Fowlkes" <shanefowlkes@h-o-t-m-a-i-l.com> wrote in message
news:%23e8Hrg1TGHA.4300@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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
>
>
>
>[/color]