下面是一個較大函數的簡單代碼片段作爲示例。使用Statement的Sqldatareader會返回一個Output參數嗎?
Using conn as New SqlConnection("conn string")
Using find as new SqlCommand("ExampleProc",conn)
Dim rParam as new SqlParameter("@RESULT",SqlDbType.Int)
rParam.Direction = ParameterDirection.Output
find.Pareameters.Add(rParam)
Using f as SqlDataReader = find.ExecuteReader
'Do stuff with datareader
End Using
updateResult.Success = Convert.ToBoolean(find.Parameters("@RESULT").Value)
End Using
End Using
我知道Output參數是在SqlDataReader關閉後返回的。從我認爲我知道的情況來看,Using語句將在SqlDataReader上調用.Dispose
,那麼基本上會消除Output參數?如果是這樣,調用一個SqlDataReader的最佳方法是什麼,該方法也包含關閉和正確處理所有內容的輸出參數?在我的搜索中我找不到任何具體的信息或示例。謝謝!
讓我補充一點,根據我讀過使用一個SqlDataReader你調用SqlDataReader中.Close後,你只能訪問輸出參數。
處理讀者應該隻影響一個對象(以及它擁有的任何對象或資源)。我認爲它不應該刪除命令中的任何內容。 – svick