R
Ronald S. Cook
In my middle tier, I, of course, often return data to the presentation
layer. When needing a forward-only, read-only list, I think of the
SqlDataReader (of course). However, since you can't close the connection
before returning the data, the line at the end of the function is what I've
found to use (i.e. CommandBehavior.CloseConnection). HOWEVER, I've heard
this sometimes doesn't always work properly and I should stick to using
DataTables instead.
Have you heard this? Or, do you think the below is just fine?
*****************************************************
Public Function UserList(ByVal iclientno As Integer) As SqlDataReader
'Return the list of userid from the user table based on a client number.
Dim dbConnection As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringKamtechLogin"))
Dim spCommand As New SqlCommand("spGetUsers", dbConnection)
spCommand.CommandType = CommandType.StoredProcedure
Dim paramClientNo As New SqlParameter("@ClientNo", SqlDbType.Int)
spCommand.Parameters.Add(paramClientNo)
paramClientNo.Direction = ParameterDirection.Input
paramClientNo.Value = iclientno
dbConnection.Open()
Dim dr As SqlDataReader =
spCommand.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
End Function
*****************************************************
Thanks,
Ron
layer. When needing a forward-only, read-only list, I think of the
SqlDataReader (of course). However, since you can't close the connection
before returning the data, the line at the end of the function is what I've
found to use (i.e. CommandBehavior.CloseConnection). HOWEVER, I've heard
this sometimes doesn't always work properly and I should stick to using
DataTables instead.
Have you heard this? Or, do you think the below is just fine?
*****************************************************
Public Function UserList(ByVal iclientno As Integer) As SqlDataReader
'Return the list of userid from the user table based on a client number.
Dim dbConnection As New
SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringKamtechLogin"))
Dim spCommand As New SqlCommand("spGetUsers", dbConnection)
spCommand.CommandType = CommandType.StoredProcedure
Dim paramClientNo As New SqlParameter("@ClientNo", SqlDbType.Int)
spCommand.Parameters.Add(paramClientNo)
paramClientNo.Direction = ParameterDirection.Input
paramClientNo.Value = iclientno
dbConnection.Open()
Dim dr As SqlDataReader =
spCommand.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
End Function
*****************************************************
Thanks,
Ron