SortedList Collection - How to enumerate....?

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*****
 
C

CJ Taylor

Lookup IEnumerable interface. you have to implement that in order to do
this.

Or IEnumerator, I can't remember which one it is. But one only makes you
use the 3 base functions. If it doens't implement, it doesn't know to
enumerate. Because you need the function getEnumerator() as well.

Welcome to object inheritance and interfacing. =)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top