在page_load上从DataTable读取数据。怎么样? [英] Read data from DataTable on page_load. How?
问题描述
我有一个在page_load中调用的函数,这个
函数的目的是在MSSQL表中查找基本数据并以表格形式返回
一个数据表。 page_load将读取数据,然后填写一些简单的
标签。
**假设**我正确编写了函数,我究竟能怎样写
page_load子来读取函数中的数据?我已经尝试了几个例子,我从几本书中得到了b $ b,但似乎无法获得一个有效的模型。我会回去
然后在基础知识到位后添加try / catch到这个功能
和工作。
非常感谢帮助和帮助!我在查看page_load子中的数据时遇到了麻烦
。使用ASP / VB .NET 2.
受保护的子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作为字符串
dsCapData =新数据集()
dtAppData = DaysLeftInAppSeason(1)
''在这里遇到麻烦
每个dtRow在dtAppData中
intDaysLeft = dtAppData(" DaysLeft")
strCloseDate = dtAppData(" CloseDate")
下一页
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
End Sub
受保护的函数DaysLeftInAppSeason(ByVal intAppID As Integer)As
DataTable
Dim objConnection As SqlConnection
Dim cmdSelect As SqlCommand
Dim drAppData As SqlDataReader
Dim dtResponse A s DataTable
Dim dtColumn As DataColumn
Dim dtRow As DataRow
Dim strConnectString As String
Dim strSQL As String
strConnectString = System.Web.Configuration .....等....
strSQL =" SELECT CloseDate,DateDiff(Day,GetDate( ),CloseDate)AS DaysLeft
来自ListAppTypes WHERE ID =" &安培; intAppID
objConnection =新的SqlConnection(strConnectString)
cmdSelect =新的SqlCommand(strSQL,objConnection)
dtResponse =新的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()
返回dtResponse
结束功能
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
推荐答案
让这个问题更加模糊或者说
$可能会更难b $ b不准确。
遇到麻烦没有任何意义。您需要向我们展示相关代码
片段,并说明您希望发生什么与确切发生的事情 -
意思是确切的错误消息,哪一行#,等等
" D. Shane Fowlkes < SH ********** @ h-o-t-m-a-i-l.com>在留言中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
It would probably be harder to have this question be more vague or
non-precise.
"Having trouble" does not mean anything. You need to show us relevant code
snippets, and say what you expect to happen vs exactly what is happening -
meaning exact error messages, which line #, etc.
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
我有在page_load中调用的函数,此函数的目的是在MSSQL表中查找基本数据并以数据表的形式返回它。 page_load将读取数据,然后填写一些简单的标签。
**假设**我正确编写了函数,我怎么能写出page_load sub从函数中读取数据?我已经尝试过几本书中的几个例子,但我似乎无法获得一个有效的模型。一旦
基础知识到位并正常工作,我会回过头来添加try / catch功能。
非常感谢帮助和帮助!我在阅读page_load子中的数据时遇到了麻烦。使用ASP / VB .NET 2.
受保护的子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)
'在这里发生故障
每个dtRow在dtAppData中
intDaysLeft = dtAppData(" DaysLeft")
strCloseDate = dtAppData(" CloseDate")
下一页
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
结束子
受保护的函数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 =新的SqlConnection(strConnectString)
cmdSelect =新的SqlCommand(strSQL,objConnection)
dtResponse =新的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()
返回dtResponse
结束功能
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
见下文:
''疑难解答这里
每个dtRow在dtAppData中
intDaysLeft = dtAppData(" DaysLeft")
strCloseDate = dtAppData(" CloseDate")
下一页
''在这里遇到麻烦
每个dtRow在dtAppData中
intDaysLeft = dtRow(" DaysLeft")
strCloseDate = dtRow( CloseDate)
下一页
''你是为每个dtRow(DataRow)写的,所以你需要
才能使用dtRow对象获取你的数据,而不是dtAppData(数据表)
peter
-
联合创始人,Eggheadcafe.com开发者门户网站:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
" D. Shane Fowlkes写道:
See below:
''TROUBLE HERE
For Each dtRow In dtAppData
intDaysLeft = dtAppData("DaysLeft")
strCloseDate = dtAppData("CloseDate")
Next
''TROUBLE HERE
For Each dtRow In dtAppData
intDaysLeft = dtRow("DaysLeft")
strCloseDate = dtRow("CloseDate")
Next
'' you are writing for each dtRow (DataRow), so you need
to use the dtRow object to get your data, not the dtAppData( the datatable)
peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"D. Shane Fowlkes" wrote:
我有一个在page_load中调用的函数,这个函数的目的是在MSSQL表中查找基本数据并以表格形式返回<数据表的数据库。 page_load将读取数据,然后填写一些简单的
标签。
**假设我正确编写了函数,我怎么能写出
page_load子从函数中读取数据?我从几本书中尝试了几个例子,但似乎无法获得一个有效的模型。一旦基础知识到位并且正常工作,我会回来并添加try / catch到该功能。
非常感谢帮助和帮助!我在阅读page_load子中的数据时遇到了麻烦。使用ASP / VB .NET 2.
受保护的子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)
'在这里发生故障
每个dtRow在dtAppData中
intDaysLeft = dtAppData(" DaysLeft")
strCloseDate = dtAppData(" CloseDate")
下一页
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
结束子
受保护的函数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 =新的SqlConnection(strConnectString)
cmdSelect =新的SqlCommand(strSQL,objConnection)
dtResponse =新的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()
返回dtResponse
结束功能
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
谢谢。
我问你这个问题。假设我的函数正常工作,你是如何成为一个更有经验的.NET开发人员,写一个page_load子来读取
数据表?那就是我被困住的地方。
Marina Levit [MVP]" <所以***** @ nospam.com>在消息中写道
news:ec ************** @ TK2MSFTNGP14.phx.gbl ...
Thanks.
Let me ask you this. Assuming my function works properly, how would YOU,
being a more experienced .NET developer, write a page_load sub to read the
datatable? That''s where I''m stuck.
"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
这可能会更难使这个问题更加模糊或不准确。
遇到麻烦没有任何意义。您需要向我们展示相关代码
片段,并说出您期望发生的事情与确切发生的事情 -
意味着确切的错误消息,行#等等。
" ; d。 Shane Fowlkes < SH ********** @ h-o-t-m-a-i-l.com>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
It would probably be harder to have this question be more vague or
non-precise.
"Having trouble" does not mean anything. You need to show us relevant code
snippets, and say what you expect to happen vs exactly what is happening -
meaning exact error messages, which line #, etc.
"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
我的功能是在page_load中调用,此函数的目的是在MSSQL表中查找基本数据并以数据表的形式返回它。 page_load将读取数据,然后填写一些简单的标签。
**假设**我正确编写了函数,我怎么能写出page_load sub从函数中读取数据?我已经尝试过几本书中的几个例子,但我似乎无法获得一个有效的模型。一旦
基础知识到位并正常工作,我会回过头来添加try / catch功能。
非常感谢帮助和帮助!我在阅读page_load子中的数据时遇到了麻烦。使用ASP / VB .NET 2.
受保护的子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)
'在这里发生故障
每个dtRow在dtAppData中
intDaysLeft = dtAppData(" DaysLeft")
strCloseDate = dtAppData(" CloseDate")
下一页
lblLabel1.Text = intDaysLeft
lblLabel2.Text = strCloseDate
结束子
受保护的函数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 =新的SqlConnection(strConnectString)
cmdSelect =新的SqlCommand(strSQL,objConnection)
dtResponse =新的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()
返回dtResponse
结束功能
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
这篇关于在page_load上从DataTable读取数据。怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!