Hello - I'm new to VB.Net programming but I've learned a few tricks in this forum and on the tutorials.
I'm trying to get a CSV-formatted text file to populate a combo box. I have the code below working in a button to send the data to the output window. What do I need to do to get it to fill in the combo box instead? And can this data be filtered? For example, my data has a name and a color. Can I send only the data that includes the color "green" to the combo box?
Thanks in advance!
Brian
I'm trying to get a CSV-formatted text file to populate a combo box. I have the code below working in a button to send the data to the output window. What do I need to do to get it to fill in the combo box instead? And can this data be filtered? For example, my data has a name and a color. Can I send only the data that includes the color "green" to the combo box?
Thanks in advance!
Brian
Imports System.IO
Imports System.Data.OleDb
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndataview.Click
Dim fileName As String = "d:\Data\rosters.csv"
Dim dirName As String = Path.GetDirectoryName(Application.ExecutablePath)
Dim dt As DataTable
Using cn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;" & _
"Data Source=" & dirName & ";" & _
"Extended Properties=""Text;HDR=Yes;FMT=Delimited""")
' Open the connection
cn.Open()
' Set up the adapter
Using adapter As New OleDbDataAdapter( _
"SELECT * FROM " & fileName, cn)
dt = New DataTable("Customer")
adapter.Fill(dt)
End Using
End Using
For Each dr As DataRow In dt.Rows
Debug.Print("{0}: {1}, {2} LastUpdated: {3}", _
dr("Num"), _
dr("FName"), _
dr("LName"), _
dr("Color"))
Next
End Sub
End Class