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. copying arrays

copying arrays

Scheduled Pinned Locked Moved Visual Basic
questiondata-structures
6 Posts 3 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.
  • B Offline
    B Offline
    brieg1000
    wrote on last edited by
    #1

    Private Joe as Array Dim lookupRows() As DataRowView = overrideView.FindRows(New Object() {"lookup_address"}) Simple prob but I'm having a b**ch figuring it out. lookupRows returns an array. how can i copy the returned array to Joe?? Thanks all Bill

    N 1 Reply Last reply
    0
    • B brieg1000

      Private Joe as Array Dim lookupRows() As DataRowView = overrideView.FindRows(New Object() {"lookup_address"}) Simple prob but I'm having a b**ch figuring it out. lookupRows returns an array. how can i copy the returned array to Joe?? Thanks all Bill

      N Offline
      N Offline
      Nick Seng
      wrote on last edited by
      #2

      The following code should work:

      Array.Copy(lookupRows,Joe,lookupRows.Length)

      Notorious SMC


      The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
      Get your facts first, and then you can distort them as much as you please Mark Twain

      B 1 Reply Last reply
      0
      • N Nick Seng

        The following code should work:

        Array.Copy(lookupRows,Joe,lookupRows.Length)

        Notorious SMC


        The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
        Get your facts first, and then you can distort them as much as you please Mark Twain

        B Offline
        B Offline
        brieg1000
        wrote on last edited by
        #3

        I tried that and got an error: Value cannot be null. Parameter name:destinationArray. Which is kinda silly I think but. . . I also tried CopyTo which produced the same error.

        Richard DeemingR 1 Reply Last reply
        0
        • B brieg1000

          I tried that and got an error: Value cannot be null. Parameter name:destinationArray. Which is kinda silly I think but. . . I also tried CopyTo which produced the same error.

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Joe = Array.CreateInstance(GetType(DataRowView), lookupRows.Length)
          Array.Copy(lookupRows,Joe,lookupRows.Length)


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          B 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            Joe = Array.CreateInstance(GetType(DataRowView), lookupRows.Length)
            Array.Copy(lookupRows,Joe,lookupRows.Length)


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            B Offline
            B Offline
            brieg1000
            wrote on last edited by
            #5

            OK That worked THANKS !! What if I need Joe to be an array of string ?? How could I / can I "typecast" this to a string array ?? Thanks again for the help so far !! Bill

            Richard DeemingR 1 Reply Last reply
            0
            • B brieg1000

              OK That worked THANKS !! What if I need Joe to be an array of string ?? How could I / can I "typecast" this to a string array ?? Thanks again for the help so far !! Bill

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Array.Copy won't work, since there isn't a direct cast from DataRowView to String. You'll need to copy the array manually:

              Joe = Array.CreateInstance(GetType(String), lookupRows.Length)
              Dim i As Integer
              For i = 0 To lookupRows.Length - 1
              Joe.SetValue(lookupRows(i).ToString(), i)
              Next

              However, since DataRowView doesn't override the ToString function, you'll just get an array filled with the string "[System.Data.DataRowView]". The DataRowView class isn't serializable, so you would need to write your own function to convert it to a string.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              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