copying arrays
-
-
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
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 -
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 -
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.
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
-
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
-
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
Array.Copy
won't work, since there isn't a direct cast fromDataRowView
toString
. 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)
NextHowever, since
DataRowView
doesn't override theToString
function, you'll just get an array filled with the string "[System.Data.DataRowView]". TheDataRowView
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