Visual Basic编程组合框问题

时间:2019-06-14 09:47:30

标签: vb.net winforms combobox

如何在应用程序中使用environment.username代码在组合框中显示当前系统用户,或列出曾经登录该PC的每个人?

当前代码:

Private Sub FrmLogin2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'loading the Computer user account in the current pc
    Dim WSHNetwork = CreateObject("WScript.Network")
    Dim strUser = ""

    strUser = Environment.UserName
    lblDispalyWinUser.Text = Environment.UserName

    Dim con As SqlConnection = New SqlConnection("Data Source=SRD-WSJHBAP12\CALCTOOL;Initial Catalog=CalcToolDB;User ID=sa;Password=P@ssw0rd")
    Dim cmd As SqlCommand = New SqlCommand("Select EmpNo, Username, Password from UserLogin ", con)
    Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
    'Dim dt As DataTable = New DataTable()
    Dim ds As New DataSet()
    Dim rd As SqlDataReader

    con.Open()
    con.Close()

    Try
        con.Open()
        sda.Fill(ds)
        sda.Dispose()
        cmd.Dispose()
        con.Close()

        'cboUsername.DataSource = ds.Tables(0)
        cboUsername.ValueMember = "Environment.UserName"
        cboUsername.DisplayMember = "Environment.UserName"

    Catch ex As Exception
        MessageBox.Show("can not open connection ! ")
    End Try

0 个答案:

没有答案