注册 登录
编程论坛 VB.NET论坛

求VB2015中,combobox1控件加载Access创建的表中的项目的方法

lhfwhrlzh 发布于 2017-06-20 01:56, 3043 次点击
VB2015创建的登录窗体中,用combobox1控件加载程序相对路径中用Access 2010创建的“XTDL”数据库中的“User”表的第一个字段中的所有用户,求代码。谢谢大神指点!原来用VB6写的代码完全不能用,跪求高人指点!谢谢!

    Private Sub frmLogin_Activated(sender As Object, e As EventArgs) Handles Me.Activated

      
    End Sub  
3 回复
#2
xyxcc1772017-07-17 15:17
回复 楼主 lhfwhrlzh
Dim strCon As String = "连接字符串"
        Dim connection As New OleDb.OleDbConnection(strCon)
        connection.Open()
        Dim strSql As String = "select username from user"
        Dim dt As New DataTable
        Dim da As New OleDb.OleDbDataAdapter(strSql, connection)
        da.Fill(dt)
        With combobox1
            .DataSource = dt
            .DisplayMember = "username"
            .ValueMember = "username"
        End With
        connection.Close()
#3
lhj564598972017-07-28 15:22
    2楼赞 .DisplayMember = "username"不用就可以
#4
lhfwhrlzh2018-02-05 00:04
回复 2楼 xyxcc177
谢谢!
1