none
update combo box RRS feed

  • Question

  • guys can u help me on how to update combo box that has data from MySQL database, and when I add into the  database the combo box will update without closing the form

    thank you in advance

    Tuesday, September 11, 2018 11:58 AM

Answers

  • Hi,

    Timer  check update.

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    
            Dim t As New Timer With {.Interval = 2000, .Enabled = True}
            AddHandler t.Tick, Sub()
                                   Using conn = New SqlConnection(constr)
                                       conn.Open()
                                       sda = New SqlDataAdapter("Select * From Student", conn)
                                       dt = New DataTable()
                                       sda.Fill(dt)
                                   End Using
                                   ComboBox1.DataSource = dt
                                   ComboBox1.DisplayMember = "Uesr Id"
                                   ComboBox1.ValueMember = "Uid"
                               End Sub
        End Sub
    End Class

    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.

    Wednesday, September 12, 2018 1:54 AM

All replies

  • No matter the database the process is the same and with that I invite you to look at one example where I use MS-Access but the logic remains the same for MySql and SQL-Server. The example also implements auto complete.

    Note I use a TextBox but note in the last example I use a ComboBox/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Tuesday, September 11, 2018 12:15 PM
    Moderator
  • Hi,

    Timer  check update.

    Imports System.Data.SqlClient
    Public Class Form1
        Dim constr As String = "Data Source = (localdb)\MSSQLLocalDB; Integrated Security = True ;AttachDbFileName= C:\Users\alexl2\Desktop\DataBase\Alex\alex.mdf"
        Dim conn As SqlConnection
        Dim sda As SqlDataAdapter
        Dim dt As DataTable
        Dim bind As New BindingSource
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
    
            Dim t As New Timer With {.Interval = 2000, .Enabled = True}
            AddHandler t.Tick, Sub()
                                   Using conn = New SqlConnection(constr)
                                       conn.Open()
                                       sda = New SqlDataAdapter("Select * From Student", conn)
                                       dt = New DataTable()
                                       sda.Fill(dt)
                                   End Using
                                   ComboBox1.DataSource = dt
                                   ComboBox1.DisplayMember = "Uesr Id"
                                   ComboBox1.ValueMember = "Uid"
                               End Sub
        End Sub
    End Class

    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.

    Wednesday, September 12, 2018 1:54 AM