0
我應該首先聲明,我認爲這個問題的答案是NO,但我想要求確定.....如果您在函數內部打開sqlconnection(使用USING塊),並在到達塊結束之前從該函數返回,那麼該連接是否會被正確處理?在處理sqlconnection之前從函數返回
例如:
Public Function Myfunction() As Boolean
Dim ConnectionString As String = "connectionstring goes here"
Dim sql As String = "SELECT * FROM mytable"
Using connection As New SqlClient.SqlConnection(ConnectionString)
Using command As New SqlClient.SqlCommand(sql, connection)
connection.Open()
Using reader As SqlClient.SqlDataReader = command.ExecuteReader
While reader.Read
Return True
End While
End Using
End Using
End Using
Return False
End Function
將上述連接被佈置如果適當地執行返回真實線的?
試試吧,找出來。 – Servy