Home > Software engineering >  SQL table to Array to check in VB Forms
SQL table to Array to check in VB Forms

Time:06-04

Let's say I have a table People (ID, DateBirth, Sex, Salary) and I do

SELECT ID 
FROM PEOPLE

Now I will get a result set with 1 column and N rows. How can I convert this table (see table) to an array, like

array = [ 101, 19, 33, 50, 6, 9 ]

After this I want to obtain that array in a Forms developed in Visual Basic to check with and If condition like this:

If i in array Then
    Update ....
End If

Any ideas on how to solve this problem?

CodePudding user response:

I am not sure “why” you need the array; however, the following code should give you what you want… assuming the id field is an Integer type in the People DataTable

Dim arrayData = (From dataRow In People.AsEnumerable() Select dataRow.Field(Of Integer)("id")).ToArray()

In my small tests, this worked as expected.

  • Related