Results 1 to 4 of 4

Thread: [RESOLVED] Convert System.Object to datatable or Array

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [RESOLVED] Convert System.Object to datatable or Array

    I'm pulling data from a D3 database, using an api.

    The api can do the following:
    Dim OBJ As Object = mvsp.MVResultSetGetRows.ToArray()

    But how do I get that data into a datatable to use as the datasource for a DataGridView?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Convert System.Object to datatable or Array

    object is the universal datatype. to help you we need to know the actual type of array that this:

    vb Code:
    1. mvsp.MVResultSetGetRows.ToArray()
    is returning

  3. #3

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Convert System.Object to datatable or Array

    Quote Originally Posted by .paul. View Post
    object is the universal datatype. to help you we need to know the actual type of array that this:

    vb Code:
    1. mvsp.MVResultSetGetRows.ToArray()
    is returning
    Hi Paul. The D3 database passed a flat file (1-dim array).
    I fixed my problem by looping obj, split on delimiter and populating a datatable.

    This will process about 600 000 records in under a second, that is quick enough for me.

    Thanks a lot for trying to help Paul, I really appreciate the great help and attitude from the people on this forum. You guys have really been helpfull, thanks

  4. #4

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: [RESOLVED] Convert System.Object to datatable or Array

    vb Code:
    1. Dim OBJ As Object = mvsp.MVResultSetGetRows.ToArray()
    2.  
    3.                 Dim MyFields As String() = Split(MY_D3_Fields, " ")
    4.  
    5.                 For i As Integer = 0 To MyFields.Length - 1
    6.                     dt.Columns.Add(MyFields(i))
    7.                 Next
    8.                 Dim Li = 0, cnt As Integer = OBJ.length
    9.                 Do Until Li = cnt
    10.                     Try
    11.  
    12.                         Dim tmp As String() = Split(OBJ(Li).ToString, "þ")
    13.                         Dim cols As Integer = tmp.Length
    14.                         Dim v(cols - 1) As Object
    15.                         For c As Integer = 0 To cols - 1
    16.                             v(c) = tmp(c)
    17.                         Next
    18.  
    19.                         dt.Rows.Add(v)
    20.                     Catch ex As Exception
    21.                     End Try
    22.                     Li += 1
    23.                 Loop
    24.                 MY_DT = New DataTable
    25.                 MY_DT = dt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width