Jumat, 12 Agustus 2011

Menampilkan data mysql di combobox VB 6.0

Berikut adalah contoh kode program menampilkan data dari tabel mysql ke combobox vb 6.0

Membuat Fungsi Combolist
Public Function ComboList(objectToIgnore As ComboBox, rs As ADODB.Recordset, Table As String, field As String, where As String, contents1 As String, contents2 As String)
On Error GoTo ErrComboList
    rsClose rs
    sql = "select " & field & " from " & Table & " " & where
    rs.Open sql, cn, adOpenDynamic, adLockPessimistic
        While Not rs.EOF
            objectToIgnore.AddItem rs.Fields(contents1) & " - " & rs.Fields(contents2)
            rs.MoveNext
        Wend
    rsClose rs
Exit Function
ErrComboList:
    MsgBox "Maaf data tidak bisa ditampilkan di combobox." + Err.Description, vbCritical
End Function

Memanggil Fungsi Combolist di Sub initCombo
Private Sub initCombo()
    combo = ComboList(Combo1, rs, "tbl_status", "*", "order by id_status asc", "id_status", "status")
End Sub

Memanggil Sub initCombo ketika Form dijalankan
Private Sub Form_Load()
    initCombo
End Sub

0 komentar:

Posting Komentar

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Justin Bieber, Gold Price in India