[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
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.