title: How do I copy values of one array to another in VB.NET?
body: <p>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,</p>
  
  <blockquote>
    <p><em>Object reference not set to an instance of an object</em>.</p>
  </blockquote>
  
  <p>I don't seem to see what is wrong. How can I fix this problem?</p>
  
  <p>My code is here:</p>
  
  <pre><code>    ' 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) &amp; ", " &amp; _
                                    reader.GetValue(2) &amp; ", " &amp; _
                                    reader.GetValue(3) &amp; ", " &amp; _
                                    reader.GetValue(6) &amp; ", " &amp; _
                                    reader.GetValue(7) &amp; ", " &amp; _
                                    reader.GetValue(8) &amp; ", " &amp; _
                                    reader.GetValue(9) &amp; ", " &amp; _
                                    reader.GetValue(10) &amp; ", " &amp; _
                                    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)
  </code></pre>