dcsimg
Results 1 to 2 of 2

Thread: [RESOLVED] How do I populate an array while creating a datatable? Breaking it up instead of fill

  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] How do I populate an array while creating a datatable? Breaking it up instead of fill

    I want to modify this function to populate an array with each item in the database.

    I have tried various options, but I just can't get it to work


    Private Function ConnectMe() As DataTable
    Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wswc;Uid=root;Pwd=Jack"
    Dim cmd As String = "SELECT * FROM st_users"
    Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
    Dim topics As New DataSet()
    ad.Fill(topics)
    ConnectMe = topics.Tables(0)
    End Function

    Instsead of fill, I want to one by one add it to the dataset and also an array

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,292

    Re: How do I populate an array while creating a datatable? Breaking it up instead of

    Why would you want to use arrays in this particular case? There's really no need for an array here because you can access the data directly from your datatable. However, if you insists on using an array, each the datarow has a public member ToItemArray which will return all items (values) of the datarow in an array of type Object. So just loop thru your datatable.rows and call the row.ToItemArray method to get the item array of that row.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width