2

I'm trying to populate an array from a dataset with only a specific column using VB.NET 2010. Is there any code to populate the array directly or must I make use of a query?

2 Answers 2

4

Update:

Assuming you want an array of String:

Dim arr As String() = (From myRow In ds.Tables(0).AsEnumerable
                       Select myRow.Field(Of String)("yourColumnName")).ToArray

or a list:

Dim list As List(Of String) = (From myRow In ds.Tables(0).AsEnumerable
                               Select myRow.Field(Of String)("yourColumnName")).ToList

Old:

Make sure the DisplayMember is set to the name of the column you want to see:

comboBox1.DataSource = ds.Tables(0)
comboBox1.DisplayMember= "NameOfColumn"

You might also want to set the ValueMember property to the ID field name from your dataset.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry, i made a mistake >.< | i have an array to fill and not a combobox.
No worries. I'll change my answer in that case.
1
Dim objDataSet As New DataSet

objDataSet = DataSetConsultas("SELECT Nombres, IDTarjeta from Alumnos")

Dim arr As String() = (From myRow In objDataSet.Tables(0).AsEnumerable
                    Select myRow.Field(Of String)("Nombres")).ToArray

cboAlumnos.Items.Clear()
cboAlumnos.Items.AddRange(arr)

Where Nombres, IDTarjeta are rows in the DB, and Alumnos is the name of the table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.