Results 1 to 5 of 5

Thread: [RESOLVED] VB.net/WPF:Return value in second column of data set based on value pulled from first

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    46

    Resolved [RESOLVED] VB.net/WPF:Return value in second column of data set based on value pulled from first

    Ok title sounds confusing, so let me post my code first:

    Code:
    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:
    Code:
    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
    Last edited by evanrich; Dec 7th, 2009 at 08:06 PM. Reason: fixed my own issue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width