Results 1 to 2 of 2

Thread: view data from database to combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    9

    view data from database to combobox

    please give me sample code for show id from database ke combo box. i use sql database.

  2. #2
    Addicted Member Programmation's Avatar
    Join Date
    Nov 2009
    Posts
    161

    Re: view data from database to combobox

    Example Code:

    Code:
    Dim Conn As SqlConnection = New SqlConnection("Server=.;Trusted_Connection=True;Initial Catalog=ke")
            Dim Comm As SqlCommand = New SqlCommand("SELECT ID FROM MyTableName", Conn)
            Dim dReader As SqlDataReader = Nothing
            Try
                Conn.Open()
                dReader = Comm.ExecuteReader()
                If dReader.HasRows = True Then
                    ComboBox1.Items.Clear()
                    Do While dReader.Read
                        ComboBox1.Items.Add(dReader("ID")) 'OR: ComboBox1.Items.Add(dReader(0))
                    Loop
                    dReader.Close()
                End If
            Catch ex As Exception
                MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Finally
                Conn.Dispose()
                Comm.Dispose()
            End Try
    Good luck
    Just Do It!

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