Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. using a data reader to add items to an arraylist

using a data reader to add items to an arraylist

Scheduled Pinned Locked Moved Visual Basic
databasehelpdiscussion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ssbelfast
    wrote on last edited by
    #1

    I'm trying to use a data reader to add items to an arraylist I've tried several approaches - my code always reads the database correctly ( I can see the values it finds) but then I get an exception saying Object reference not set to an instance of an object. My original ideas were something like this: Dim IdNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader While (reader.Read()) m_ID = reader("id") IdNums.Add(m_ID) End while OR Dim IDNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader Dim i As Integer = 0 While (reader.Read()) IdNums.Add(reader.GetValue(i)) End while I thought the error message meant I had to create an object so I tried Dim IDNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader Dim IDobj As string = " " While (reader.Read()) IdNums.Add(IDobj) End while but same results Any thoughts Thanks

    D 1 Reply Last reply
    0
    • S ssbelfast

      I'm trying to use a data reader to add items to an arraylist I've tried several approaches - my code always reads the database correctly ( I can see the values it finds) but then I get an exception saying Object reference not set to an instance of an object. My original ideas were something like this: Dim IdNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader While (reader.Read()) m_ID = reader("id") IdNums.Add(m_ID) End while OR Dim IDNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader Dim i As Integer = 0 While (reader.Read()) IdNums.Add(reader.GetValue(i)) End while I thought the error message meant I had to create an object so I tried Dim IDNums as arraylist Dim command As OleDbCommand = con.CreateCommand() command.CommandText = "SELECT Id from Candidates " Dim reader As IDataReader = command.ExecuteReader Dim IDobj As string = " " While (reader.Read()) IdNums.Add(IDobj) End while but same results Any thoughts Thanks

      D Offline
      D Offline
      Dave Sexton
      wrote on last edited by
      #2

      ssbelfast wrote:

      Dim IDNums as arraylist

      Try using the "New" keyword as in Dim IDNums as New ArrayList.

      S 1 Reply Last reply
      0
      • D Dave Sexton

        ssbelfast wrote:

        Dim IDNums as arraylist

        Try using the "New" keyword as in Dim IDNums as New ArrayList.

        S Offline
        S Offline
        ssbelfast
        wrote on last edited by
        #3

        thanks!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups