设计有一个登录窗口,窗体LOAD事件时,将数据库数据填充到用户组合框。填充是分别将Table.Name字段给DisplayMember,将Table.Password字段给ValueMember。用户在操作时,选中下拉用户名,然后密码文本框输入密码,点确定按钮判断密码是否正确。后台用StrComp校验PasswordBox.Text 和ComboBox.ValueMember文本是否一致。但ComboBox.ValueMember返回的值不是数据库中的数据,而是"Table.Password"代码。如果用向导数据绑定则不会出现这个问题,纯代码链接数据库则出现这个问题。
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
If StrComp(txtPassword.Text, cboUser.ValueMember, CompareMethod.Text) = 0 Then
MessageBox.Show("OK")
Else
MessageBox.Show("Not")
MessageBox.Show("密码是:" & cboUser.ValueMember)
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Application.Exit()
End Sub
Private Sub chkPasswordShow_CheckedChanged(sender As Object, e As EventArgs) Handles chkPasswordShow.CheckedChanged
If CBool(chkPasswordShow.CheckState) Then
txtPassword.PasswordChar = CChar("")
Else
txtPassword.PasswordChar = CChar("*")
End If
txtPassword.Focus()
txtPassword.SelectAll()
End Sub
Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Dim Conx As New OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0;Data Source=S:\Employee.accdb;")
Dim MyDataSet As New DataSet
Dim MyDataAdapter As New OleDbDataAdapter("SELECT * FROM tblEmployee WHERE Login <> 0 AND Leave = False", Conx)
MyDataAdapter.Fill(MyDataSet, "tblEmployee")
cboUser.DataSource = MyDataSet
cboUser.DisplayMember = "tblEmployee.Name"
cboUser.ValueMember = "tblEmployee.Password"
Conx.Close()
Catch
Exit Sub
End Try
End Sub
求指教!
------解决方案--------------------
cboUser.SelectedValue