Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

collection in vb.net

I am doing this and it errors on this line. ss = col.Item(0).ToString why? is there a better way to do this?

 
This is the code

   Dim col As New Collection

        Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand("spReturnCategoryIDByProductID ", Connection)
        'Add the parameters for the SelectCommand.
        Dim dr As SqlClient.SqlDataReader

        With command
            .Parameters.Add("@Product_ID", SqlDbType.Int)
            .Parameters("@Product_ID").Value = ProductID
            .CommandType = CommandType.StoredProcedure
            dr = .ExecuteReader
        End With


        Do While dr.Read
            col.Add(dr("Category_ID"))
        Loop

        Dim i As Integer
        For i = 1 To col.Count
            Dim ss As String
            ss = col.Item(0).ToString

        Next
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

try

If col.Count > 1 Then
For i = 1 To col.Count
  col.item(i).tostring
Next
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbnetcoder
vbnetcoder

ASKER

yu