Click here to Skip to main content
15,886,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Can anyone give me a method to convert the result of a select query to list of class?
*I want that so I can later use LINK to objects*

I'm using sql server 2008 and vb.net. For example, I have a table in DB having two columns:
SQL
{ProductID, ProductName}

I execute a select query
SQL
"Select * From Products"
and fill it in a dataset DS. I want a way so I can convert the result of the above query's result (or any query that returns any set of result) to a list of an existing class in my vb.net project, in my example Product class that has two properties (ProductID and ProductName). I hope my question is clear enough.
Posted
Updated 8-May-14 11:26am
v3

1 solution

Sample
VB
Public Class Product
    Private pid As Integer = 0
    Private pname AS String = String.Empty


    Public Property ProductID As Integer
        Get 
            Return pid
        End Get
        Set (value As Integer)
            pid = value
        End Set
    End Property


    Public Property ProductName As String
        Get 
            Return pname
        End Get
        Set (value As String)
            pname = value
        End Set
    End Property
End Class


To create collection, please follow this link: Walkthrough: Creating Your Own Collection Class[^]

Try!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900