Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6197633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:51:21+00:00 2026-05-24T03:51:21+00:00

I have my code that is reading values from a database and then putting

  • 0

I have my code that is reading values from a database and then putting them into an array. I want to copy the values of this array to another array, however when I try, it keeps on throwing an exception,

Object reference not set to an instance of an object.

I don’t seem to see what is wrong. How can I fix this problem?

My code is here:

    ' Read values from a database and assign them to an array
    Dim counter As Integer = 0
    Dim reader As MySqlDataReader
    reader = cmd.ExecuteReader()
    Dim dataarray As string()

    While reader.Read()
        Dim datatoAdd As string = reader.GetValue(1) & ", " & _
                                  reader.GetValue(2) & ", " & _
                                  reader.GetValue(3) & ", " & _
                                  reader.GetValue(6) & ", " & _
                                  reader.GetValue(7) & ", " & _
                                  reader.GetValue(8) & ", " & _
                                  reader.GetValue(9) & ", " & _
                                  reader.GetValue(10) & ", " & _
                                  reader.GetValue(11)

        dataarray(counter) = datatoAdd
    End While

    reader.Close()
    connection.Close()
    MessageBox.Show('Data added successfully)

Catch ex As Exception
    MessageBox.Show(ex.Message)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:51:22+00:00Added an answer on May 24, 2026 at 3:51 am

    Your statement

    Dim dataarray As string()
    

    just declared dataarray — you defined that dataarray can point to an array of string. Currently, it does not point anywhere. You have to create a new array and assign it to dataarray.

    The easiest way to do so is to specify the size of the array in the declaration:

    Dim dataarray(UPPER_BOUND) As String
    

    This will create an array with indexes 0 to UPPER_BOUND (i.e., with UPPER_BOUND+1 elements). (If you don’t know the upper bound yet, don’t use an array, but use a List(Of String) instead.)

    More details:

    • MSDN: Arrays in Visual Basic

    EDIT: You state in the comments that you don’t know the size of the array. In that case you shouldn’t be using an array at all. Arrays are by definition fixed-size data structures. (Yes, there’s ReDim Preserve, but it’s still not a good idea.)

    Instead, use a resizable data structure such as List(Of String). If you really need an array, you can convert it into an array afterwards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from this question I now have code that can attach to a
I have this code that performs an ajax call and loads the results into
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
I am querying information from Active Directory . I have code that works, but
I have some code that gives a user id to a utility that then
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
Hashtables have a syncroot property but generic dictionaries don't. If I have code that
I have some code that uses the shared gateway pattern to implement an inversion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.