[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How do I load data into List (Of T)

Posted on 2011-02-25
1
Medium Priority
?
429 Views
Last Modified: 2012-05-11
I am writing a new application and can't remember how to load data from a database into List(Of T).  MS Access was the best choice for this customer, so I'm using OleDB.  I have a class called Store that has the properties for the Store table's data.

How do I populate the List(Of T)?
Here's my code so far:

 
Private Sub LoadStores()
        Dim colStores As New List(Of Store)
        objConnection = objEngine.GetConnection
        Dim sql As String = "SELECT StoreID,StoreAbbreviation,StoreState,StoreName "
        sql &= "FROM Stores ORDER BY StoreName;"
        Dim cmd As New OleDb.OleDbCommand
        cmd.CommandText = sql
        cmd.ExecuteNonQuery()

    End Sub

Open in new window

0
Comment
Question by:Agent909
[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
1 Comment
 
LVL 1

Accepted Solution

by:
Agent909 earned 0 total points
ID: 34985944
I figured it out.  The code isn't 'pretty' yet, but it works.


Private Sub LoadStores()
        Dim s As New Store
        Dim r As OleDb.OleDbDataReader
        Dim colStores As New List(Of Store)
        objConnection = objEngine.GetConnection
        Dim sql As String = "SELECT StoreID,StoreAbbreviation,StoreState,StoreName "
        sql &= "FROM Stores ORDER BY StoreName;"
        Dim cmd As New OleDb.OleDbCommand
        cmd.CommandText = sql
        cmd.Connection = objConnection
        objConnection.Open()
        r = cmd.ExecuteReader
        If r.HasRows Then
            While r.Read()
                s = New Store
                s.StoreID = r("StoreID")
                s.StoreAbbreviation = r("StoreAbbreviation")
                s.StoreState = r("StoreState")
                s.StoreName = r("StoreName")
                colStores.Add(s)
            End While
            gridStores.DataSource = colStores
        Else
            MessageBox.Show("There are NO stores entered.")
        End If
        objConnection.Close()
    End Sub

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fiā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

650 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