vul*_*ino 2 mysql vb.net mysqldatareader
我曾经使用try/catch/finally块关闭一个打开的datareader:
Dim dr As MySqlDataReader = Nothing
Try
dr = DBConnection.callReadingStoredProcedure("my_sp")
Catch ex As Exception
' the caller will handle this
Throw ex
Finally
If dr IsNot Nothing Then dr.Close()
End Try
Run Code Online (Sandbox Code Playgroud)
但我认为使用"Using"VB关键字应该更干净(并且更快):
Using dr As MySqlDataReader = DBConnection.callReadingStoredProcedure("my_sp")
End Using
' dr is surely disposed, but is it closed?
Run Code Online (Sandbox Code Playgroud)
IDispose接口(使用时需要)是否在DataReader上执行关闭?
| 归档时间: |
|
| 查看次数: |
724 次 |
| 最近记录: |