嗨大家我试图创建一个由SQL查询填充的组合框,但是当我点击下拉菜单时,下面的代码没有显示任何结果,请帮助我。的Merci
Private Sub eNumText_SelectedIndexChanged(sender As Object, e As EventArgs) Handles eNumText.SelectedIndexChanged
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= c:\Databse\Company_db.accdb"
Dim cmd As New OleDbCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT EmpID from tbl_empinfo"
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read
eNumText.Items.Add(dr.Item(0))
End While
dr.Close()
答案 0 :(得分:0)
您的代码不会被触发,因为我猜ComboBox中没有项目,将您的代码移动到Button Click或Form_Load事件,它将起作用:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
'Your Code
....
End Sub