从我的sql填充数据表用于组合框

时间:2016-04-21 13:53:50

标签: vb.net combobox

 Private Sub type_km_SelectedIndexChanged(sender As Object, e As EventArgs) Handles type_km.SelectedIndexChanged
        If Not IsNothing(type_km.SelectedValue) Then
            Dim id As Integer = type_km.SelectedValue
            Call kon()
            koneksi.Open()
            cd = New MySqlCommand("SELECT no_kamar FROM km_hotel WHERE type_km='" & id & "' AND status='kosong' ORDER BY no_kamar ASC", koneksi)
            da = New MySqlDataAdapter(cd)
            dt = New DataTable
            da.Fill(dt)
            no_km.DisplayMember = "no_kamar"
            no_km.ValueMember = "no_kamar"
            no_km.DataSource = dt
        End If
    End Sub

这里我有2个组合框

> combobox1 = type_km 
> combobox2 = no_km

这是标题

> Imports MySql.Data.MySqlClient Imports System.Threading
> 
> Public Class menu_utama
>     Public koneksi As MySqlConnection
>     Public da As MySqlDataAdapter
>     Public dt As DataTable
>     Public ds As DataSet
>     Public cd As MySqlCommand
>     Public rd As MySqlDataReader
> 
>     Private Sub kon()
>         koneksi = New MySqlConnection("Data Source=localhost ;user id=root; database=hotel;")
>         Try
>             koneksi.Open()
>             koneksi.Close()
>         Catch salah As Exception
>             MsgBox("Error koneksi database : " & salah.Message)
>         End Try
>     End Sub

我尝试使用combobox2在combobox1中显示type_km的选定成员。

任何人都可以解决,为什么它没有在combobox2上显示combobox1的成员

0 个答案:

没有答案