A
Alex Stevens
Hi
I have a class which inherits the sortedlist collection.
I've overloaded the add method to allow the collection to store
sqlParameters, with the key being the parameter name.
When I try to enumerate using this code:
*****Test Code Start *****
Dim params As New MTXDataLayer.Parameters
Dim prm As SqlClient.SqlParameter
params.Add("RETURN", SqlDbType.Int)
params.Add("RETURN2", SqlDbType.Int)
params.Add("RETURN3", SqlDbType.Int)
params.Add("RETURN4", SqlDbType.Int)
MsgBox(params.Count)
For Each prm In params
MsgBox(prm.ParameterName)
Next
*****Test Code End*****
The params.count works giving 4, but the enumeration doesn't.
How can I fix this?
Thanks
Alex Stevens
*****ClassCode Start *****
Public Class Parameters
Inherits System.Collections.SortedList
Public Overloads Function Add(ByVal strParamName As String, ByVal
sqlParamType As Data.SqlDbType, _
Optional ByVal intSize As Integer = 0, Optional ByVal varValue As
Object = Nothing) As SqlClient.SqlParameter
Dim sqlParam As New SqlClient.SqlParameter
With sqlParam
.ParameterName = strParamName
.SqlDbType = sqlParamType
.Size = intSize
.Value = varValue
End With
Try
Me.Add(sqlParam.ParameterName, sqlParam)
'mColParameters.Add(sqlParam, strParamName)
Catch exc As Exception
Throw New ArgumentOutOfRangeException
End Try
Add = sqlParam
sqlParam = Nothing
End Function
End Class
*****ClassCode Code End*****
I have a class which inherits the sortedlist collection.
I've overloaded the add method to allow the collection to store
sqlParameters, with the key being the parameter name.
When I try to enumerate using this code:
*****Test Code Start *****
Dim params As New MTXDataLayer.Parameters
Dim prm As SqlClient.SqlParameter
params.Add("RETURN", SqlDbType.Int)
params.Add("RETURN2", SqlDbType.Int)
params.Add("RETURN3", SqlDbType.Int)
params.Add("RETURN4", SqlDbType.Int)
MsgBox(params.Count)
For Each prm In params
MsgBox(prm.ParameterName)
Next
*****Test Code End*****
The params.count works giving 4, but the enumeration doesn't.
How can I fix this?
Thanks
Alex Stevens
*****ClassCode Start *****
Public Class Parameters
Inherits System.Collections.SortedList
Public Overloads Function Add(ByVal strParamName As String, ByVal
sqlParamType As Data.SqlDbType, _
Optional ByVal intSize As Integer = 0, Optional ByVal varValue As
Object = Nothing) As SqlClient.SqlParameter
Dim sqlParam As New SqlClient.SqlParameter
With sqlParam
.ParameterName = strParamName
.SqlDbType = sqlParamType
.Size = intSize
.Value = varValue
End With
Try
Me.Add(sqlParam.ParameterName, sqlParam)
'mColParameters.Add(sqlParam, strParamName)
Catch exc As Exception
Throw New ArgumentOutOfRangeException
End Try
Add = sqlParam
sqlParam = Nothing
End Function
End Class
*****ClassCode Code End*****