[英]Does extracting rows from an SqlDataSource using directcast cause another trip to SQL Server?
I was looking for a way to extract data from a SqlDataSource
object within VB.NET code but looking at the code I found for this leads me to believe that the select statement is executed once again during the DirectCast
. 我一直在寻找一种从VB.NET代码中的SqlDataSource
对象提取数据的方法,但是查看为此找到的代码使我相信select语句在DirectCast
期间再次执行。
Does anyone know if this usage causes an additional select statement to be run even though the SqlDataSource
has already run previously? 有谁知道即使SqlDataSource
以前已经运行过,这种用法是否也会导致另外的select语句运行?
The post I got this from is here: How can i iterate through row of particular table associated with SqlDataSource control in VS 2008? 我从这里得到的帖子在这里: 如何在VS 2008中遍历与SqlDataSource控件关联的特定表的行?
Here is the code: 这是代码:
Dim datareader = DirectCast(SqlDataSource2.[Select](DataSourceSelectArguments.Empty), SqlDataReader)
While datareader.Read()
Label2.Text = datareader("LastName").ToString()
End While
datareader.Close()
A data reader will read from the source. 数据读取器将从源中读取。
If the source is a database, then the reader will read from the database every time you call Read()
. 如果源是数据库,则每次调用Read()
时,读取器都会从数据库中Read()
。
It is unclear to me what your DirectCast is there for or why you are using it. 我不清楚您的DirectCast有什么用途,还是为什么要使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.