D
D. Shane Fowlkes
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
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