Creating ComboBox Connected to your Database

Rabu, 29 Januari 2014

Step 1 >>>> add ComboBox into your form. (fig 1.0)


Figure 1.0















Step 2 >>>> select the ComboBox and go to its Property. (fig 1.1)


Figure 1.1















into its property, change its DropDownStyle to DropDownList.

Step 3 >>>> press F7 or go into you code and lets start coding.

on top of your code, paste the code below,

    Imports MySql.Data

    Imports MySql.Data.MySqlClient

this code use to connect into your MySql database.

inside your Private Sub Form1_Load, paste this code;

        SQLcon() //connection to your database

        ComboBox
        str = "select * from info order by Dept" // query use to select data from your table
        con.Open()
        cmd = New MySqlCommand(str, con)
        dr = cmd.ExecuteReader()
        While dr.Read

            ComboBox1.Items.Add(dr.Item("Dept"))

        End While
        con.Close()

try to run now your form if you successfully connect your ComboBox into your Database.

Related Posts by Categories

0 komentar:

Posting Komentar

Copyright © 2010 All About Tech Information | Powered By Blogger