D
D. Shane Fowlkes
I have a function that is called in page_load and the purpose of this
function is to look up basic data in a MSSQL table and return it in the form
of a datatable. The page_load will read the data and then fill a few simple
labels.
**Assuming** that I wrote the function properly, how exactly can I write the
page_load sub to read the data from the function? I've tried a few examples
from a couple of books I have but can't seem to get a working model. I'll go
back and add try/catch to the function later once the basics are in place
and working.
Help and assistance would GREATLY be appreciated! I'm having trouble
reading the data in the page_load sub. Using ASP/VB .NET 2.
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim dtAppData As DataTable
Dim dtRow As DataRow
Dim dsCapData As DataSet
Dim intDaysLeft As Integer
Dim strCloseDate As String
dsCapData = New DataSet()
dtAppData = DaysLeftInAppSeason(1)
'TROUBLE HERE
For Each dtRow In dtAppData
intDaysLeft = dtAppData("DaysLeft")
strCloseDate = dtAppData("CloseDate")
Next
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
End Sub
Protected Function DaysLeftInAppSeason(ByVal intAppID As Integer) As
DataTable
Dim objConnection As SqlConnection
Dim cmdSelect As SqlCommand
Dim drAppData As SqlDataReader
Dim dtResponse As DataTable
Dim dtColumn As DataColumn
Dim dtRow As DataRow
Dim strConnectString As String
Dim strSQL As String
strConnectString = System.Web.Configuration.....etc....
strSQL = "SELECT CloseDate, DateDiff(Day, GetDate(), CloseDate) AS DaysLeft
FROM ListAppTypes WHERE ID = " & intAppID
objConnection = New SqlConnection(strConnectString)
cmdSelect = New SqlCommand(strSQL, objConnection)
dtResponse = New DataTable("CapitalData")
dtColumn = New DataColumn("CloseDate", GetType(String))
dtColumn = New DataColumn("DaysLeft", GetType(Integer))
objConnection.Open()
drAppData = cmdSelect.ExecuteReader()
drAppData.Read()
dtRow = dtResponse.NewRow()
dtRow("CloseDate") = drAppData("CloseDate")
dtRow("DaysLeft") = drAppData("DaysLeft")
drAppData.Close()
objConnection.Close()
Return dtResponse
End Function
function is to look up basic data in a MSSQL table and return it in the form
of a datatable. The page_load will read the data and then fill a few simple
labels.
**Assuming** that I wrote the function properly, how exactly can I write the
page_load sub to read the data from the function? I've tried a few examples
from a couple of books I have but can't seem to get a working model. I'll go
back and add try/catch to the function later once the basics are in place
and working.
Help and assistance would GREATLY be appreciated! I'm having trouble
reading the data in the page_load sub. Using ASP/VB .NET 2.
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
Dim dtAppData As DataTable
Dim dtRow As DataRow
Dim dsCapData As DataSet
Dim intDaysLeft As Integer
Dim strCloseDate As String
dsCapData = New DataSet()
dtAppData = DaysLeftInAppSeason(1)
'TROUBLE HERE
For Each dtRow In dtAppData
intDaysLeft = dtAppData("DaysLeft")
strCloseDate = dtAppData("CloseDate")
Next
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
End Sub
Protected Function DaysLeftInAppSeason(ByVal intAppID As Integer) As
DataTable
Dim objConnection As SqlConnection
Dim cmdSelect As SqlCommand
Dim drAppData As SqlDataReader
Dim dtResponse As DataTable
Dim dtColumn As DataColumn
Dim dtRow As DataRow
Dim strConnectString As String
Dim strSQL As String
strConnectString = System.Web.Configuration.....etc....
strSQL = "SELECT CloseDate, DateDiff(Day, GetDate(), CloseDate) AS DaysLeft
FROM ListAppTypes WHERE ID = " & intAppID
objConnection = New SqlConnection(strConnectString)
cmdSelect = New SqlCommand(strSQL, objConnection)
dtResponse = New DataTable("CapitalData")
dtColumn = New DataColumn("CloseDate", GetType(String))
dtColumn = New DataColumn("DaysLeft", GetType(Integer))
objConnection.Open()
drAppData = cmdSelect.ExecuteReader()
drAppData.Read()
dtRow = dtResponse.NewRow()
dtRow("CloseDate") = drAppData("CloseDate")
dtRow("DaysLeft") = drAppData("DaysLeft")
drAppData.Close()
objConnection.Close()
Return dtResponse
End Function