Solved

collection in vb.net

Posted on 2011-03-11
3
335 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:vbnetcoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35113095
try

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

Open in new window

0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 35113099
actually

col.Count > 0
0
 

Author Closing Comment

by:vbnetcoder
ID: 35113144
yu
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question