none
fill ComboBox from tow table RRS feed

  • Question

  • hi

    I want to fill ComboBoxfrom two different tables

    my code not fill

       Dim oledbAdapter As OleDbDataAdapter
            Dim ds As New DataSet
            Dim sql As String
            Try
    
                sql = "SELECT DISTINCT MOBLOCALTOT_COMMODEL FROM MOBLOCALTOT_TB UNION SELECT DISTINCT MOBINTERTOT_COMMODEL FROM MOBINTERTOT_TB"
                con.Open()
                oledbAdapter = New OleDbDataAdapter(sql, con)
                oledbAdapter.Fill(ds, "MOBLOCALTOT_TB,MOBINTERTOT_TB")
                oledbAdapter.Dispose()
                con.Close()
                ComboBox1.Items.Clear()
                For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
                    ComboBox1.Items.Add(ds.Tables(0).Rows(i)(0).ToString())
                Next
                con.Close()
            Catch ex As Exception
                Exit Sub
            End Try

    Monday, February 11, 2019 3:28 AM

Answers

  • Hi,

    I tried your code,it works well.Where is the error? Are you sure the following query has returned data?

    sql = "SELECT DISTINCT MOBLOCALTOT_COMMODEL FROM MOBLOCALTOT_TB UNION SELECT DISTINCT MOBINTERTOT_COMMODEL FROM MOBINTERTOT_TB"

    fix the code,

    Catch ex As Exception
                 MsgBox(ex.ToString)
            End Try

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Monday, February 11, 2019 6:21 AM
    Monday, February 11, 2019 5:25 AM
    Moderator

All replies

  • Hi,

    I tried your code,it works well.Where is the error? Are you sure the following query has returned data?

    sql = "SELECT DISTINCT MOBLOCALTOT_COMMODEL FROM MOBLOCALTOT_TB UNION SELECT DISTINCT MOBINTERTOT_COMMODEL FROM MOBINTERTOT_TB"

    fix the code,

    Catch ex As Exception
                 MsgBox(ex.ToString)
            End Try

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ahmeddc Monday, February 11, 2019 6:21 AM
    Monday, February 11, 2019 5:25 AM
    Moderator
  • Hi,

    I tried your code,it works well.Where is the error? Are you sure the following query has returned data?

    sql = "SELECT DISTINCT MOBLOCALTOT_COMMODEL FROM MOBLOCALTOT_TB UNION SELECT DISTINCT MOBINTERTOT_COMMODEL FROM MOBINTERTOT_TB"

    fix the code,

    Catch ex As Exception
                 MsgBox(ex.ToString)
            End Try

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    thanks

    One of the tables was open

    Monday, February 11, 2019 6:21 AM