We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,382 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Items.AddRange throws exception if used more than once

Hello,

I'm having an issue with updating a couple list boxes in the form load procedure. I have an array created from a MySQL database, and when I try to add that array to more than one ListBox, I get:

A first chance exception of type 'System.ArgumentNullException' occurred in System.Windows.Forms.dll

Here is the code:

Database_Functions.UpdateNames(Names)
        Me.lstRoster_Roster.Items.Clear()
        Me.lstRoster_Roster.Items.AddRange(Names)
        Me.lstRoster_Home.Items.Clear()
        Me.lstRoster_Home.Items.AddRange(Names)

And Database_Functions.UpdateNames:

Public Sub UpdateNames(ByRef Names() As String)
        Dim sql As String = "SELECT Name FROM users"
        Dim cmd As MySqlCommand = New MySqlCommand(sql, Login.SQLConnection)
        Dim reader As MySqlDataReader = cmd.ExecuteReader()

        Do While reader.Read()
            Static i As Integer = 1
            ReDim Preserve Names(i)
            Names(i - 1) = reader.GetString(0)
            i += 1
        Loop
        reader.Close()

    End Sub

Thanks in advance for your help!

2
Contributors
1
Reply
4 Days
Discussion Span
1 Year Ago
Last Updated
2
Views
randomkid73
Newbie Poster
18 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I think you have a problem with the build of your names array. See if the value of the last entry in it is NOTHING.

Smith5646
Junior Poster in Training
65 posts since Nov 2009
Reputation Points: 34
Solved Threads: 9
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0790 seconds using 2.67MB