Reputation: 815
I have a table I am querying and then trying to use Linq to convert the itemArray into a string array.
I'm using the following
Dim ObjectMapping As DataTable = ds.Tables(0)
Dim index As Integer = 0
Dim query = From ObjectMap In ObjectMapping.AsEnumerable() Select ObjectMap
Dim test = dr.ItemArray.Cast(Of String)().ToArray()
The table has 13 columns and the ItemArray contains
(0) - "string"
(1) - double
(2) - "string"
(3) - "string"
(4) - DBNull
(5) - DBNull
(6) - DBNull
(7) - DBNull
(8) - DBNull
(9) - DBNull
(10) - DBNull
(11) - DBNull
(12) - DBNull
When I try to Cast the ItemArray into a String array, it dies due to the 2nd column containing a Double value, rather than String. Is there a way I can convert this column prior to casting the whole array? Or would the only way to fix this is to change the schema of the table?
Upvotes: 0
Views: 566
Reputation: 152541
No, you can't cast, but you can convert:
Dim test = dr.ItemArray.Select(Function (o) o.ToString()).ToArray()
Upvotes: 1