Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to display the result from a query in a combobox immediately

Status
Not open for further replies.

Xsi

Programmer
May 29, 2015
121
SE
Hello people,

I have made following code,
I wonder how do I change the Handles to display the result from my query immediately?

see code below:

Code:
 Private Sub Cbx_Year_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cbx_Year.SelectedIndexChanged

        Dim Combobox As ComboBox = CType(sender, ComboBox)
        If Cbx_Year.SelectedItem IsNot Nothing Then
            Dim CurrentVal = CType(Cbx_Year.SelectedItem, String)
            '  MsgBox(CurrentVal)
        End If

        Dim Year_List_HashTable As New List(Of Integer)
        Dim Years_list As List(Of Integer)
        Dim dt As New DataTable()
        Dim dv As New DataView(dt)
        Dim ConnectionString As String = "Data Source=ttdev\Teknotrans_dev;Initial Catalog=myDatabase;Integrated Security=True"
        Dim myconn As New SqlConnection(ConnectionString)
        myconn.Open()
        Using da As New SqlDataAdapter("SELECT DISTINCT [t0].[bestdatum] AS [Bestdatum]FROM [OpusOrder] AS [t0]", myconn)
            da.Fill(dt)
        End Using
        myconn.Close()
        Dim Years_Table As DataTable = dv.ToTable(True, "Bestdatum") ' tabellen ur databasen samt kolumen med datan
        For Each customer As DataRow In Years_Table.Rows
            Dim Year_Item = (customer("Bestdatum").ToString)
            Dim Year_String As String = (Year_Item.Substring(0, Year_Item.Length - 15))
            Year_List_HashTable.Add(Year_String)
        Next
        Years_list = Year_List_HashTable.Distinct().ToList ' Ta bort dubletter
        Years_list.Sort()
        For Each item In Years_list
            Cbx_Year.Items.Add(item)
        Next
        Cbx_Year.SelectedIndex = 0

    End Sub

Could someone help me ?

Thank you in advance
 
I found this work but is this the best way to make it?

Code:
Private Sub Cbx_Year_TabIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cbx_Year.TabIndexChanged
 
I don't understand the issue. When are the query results being displayed now?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top