evanrich
Dec 7th, 2009, 06:58 PM
Ok title sounds confusing, so let me post my code first:
Private Sub ASPCustSelection_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:" & "\;Extended Properties='text;HDR=Yes'"
CommandText = "select * from aspcustomers.txt"
conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
Command = New System.Data.OleDb.OleDbCommand(CommandText, conn)
conn.Open()
da = New OleDbDataAdapter(CommandText, conn)
ds = New DataSet
' fill dataset
da.Fill(ds, "ASPCustomers")
For Count = 0 To ds.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(ds.Tables(0).Rows(Count)(0))
Next
This loads the contents of a CSV file into a dataset, formatted as such:
2281jufr97,Allied Technology
5246ydxk84,ASC DET1
and then fills a combo box with the "Company name" pulled from that list. What I need to do however, is pull the company CODE, the number/letter combination, and then pass that as a variable to another function later on.
I thought I had it when i put this code in as a test:
TextBox1.Text = (ds.Tables(0).columns(ComboBox1.SelectedIndex).ToString)
but after the second value it would crash, saying it couldn't find column "2".
How can i use the selected index from the combo box to pull the matching company code?
EDIT: I fixed it..I needed the following code in my "selection changed" event:
TextBox1.Text = (ds.Tables(0).Rows(ComboBox1.SelectedIndex)).Item(1)
This works :)
Private Sub ASPCustSelection_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:" & "\;Extended Properties='text;HDR=Yes'"
CommandText = "select * from aspcustomers.txt"
conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
Command = New System.Data.OleDb.OleDbCommand(CommandText, conn)
conn.Open()
da = New OleDbDataAdapter(CommandText, conn)
ds = New DataSet
' fill dataset
da.Fill(ds, "ASPCustomers")
For Count = 0 To ds.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(ds.Tables(0).Rows(Count)(0))
Next
This loads the contents of a CSV file into a dataset, formatted as such:
2281jufr97,Allied Technology
5246ydxk84,ASC DET1
and then fills a combo box with the "Company name" pulled from that list. What I need to do however, is pull the company CODE, the number/letter combination, and then pass that as a variable to another function later on.
I thought I had it when i put this code in as a test:
TextBox1.Text = (ds.Tables(0).columns(ComboBox1.SelectedIndex).ToString)
but after the second value it would crash, saying it couldn't find column "2".
How can i use the selected index from the combo box to pull the matching company code?
EDIT: I fixed it..I needed the following code in my "selection changed" event:
TextBox1.Text = (ds.Tables(0).Rows(ComboBox1.SelectedIndex)).Item(1)
This works :)