我在 ASP.NET 中进行了很多开发,并且我知道每个 SQLConnection 只能打开一个 SQLDataReader。但是,在 VB.NET(表单应用程序)中似乎并非如此,即我为一个连接对象打开了多个 SQLDataReader。这在 VB.NET 中是否允许?
如果对此没有明显的答案,那么我将发布一些代码。
这是一些代码:
Public Function CheckActiveReviews()
Dim objCon As SqlConnection
Dim objCommand As SqlCommand, objCommand2 As SqlCommand
Dim objDR As SqlDataReader, objDR2 As SqlDataReader
Try
objCon = New SqlConnection("Data Source=TestDatabase;Initial Catalog=TestTable;User ID=TestUser;Password=TestPassword;MultipleActiveResultSets=True")
objCommand = New SqlCommand
objCommand.Connection = objCon
objCommand2 = New SqlCommand
objCommand2.Connection = objCon
objCon.Open()
objCommand.CommandText = "SELECT ID FROM Person WHERE PersonID > 1000"
objDR = objCommand.ExecuteReader()
Do While objDR.Read
objCommand2.CommandText = "SELECT * FROM Sport WHERE PersonID = @PersonID "
objCommand2.Parameters.AddWithValue("@PersonID", objDR("ID"))
objDR2 = objCommand2.ExecuteReader
Loop
Catch ex As Exception
End Try
End Function