Dim list As New List(Of Integer)
Using reader As SqlDataReader = command .ExecuteReader()
While reader.Read()
list.Add(reader.GetInt32(reader.GetOrdinal("ProductID")))
End While
End Using
'check list.ToArray() now
EDIT : But, Instead of return an Array, i Would return a Generic List of Integers (if you only want to return the ProductId) or A List of ProductClass objects
Private Function GetProductIDs() As IList(Of Integer)
Dim list As New List(Of Integer)
Dim conStr = "write your connection string here"
Using connection As New SqlConnection(conStr )
Dim sql As String = "Select ProductID From OrderDetail Order By ProductID Desc"
Dim command As New SqlCommand(sql, connection)
Using reader As SqlDataReader = command.ExecuteReader()
While reader.Read()
list.Add(reader.GetInt32(reader.GetOrdinal("ProductID")))
End While
End Using
End Using
Return list
End Function
EDIT 2 : As per the comment,
To retrieve an put in the Text of a label, you can do this
Dim str As String
str = String.Join(",", GetProductIDs())
Label1.Text=str;
Assuming Label1 is theI D of your label control.The String.Join method will return a string of ProductId's seperated by comma like "1,2,6,7"