以下是引用Bin在2014-4-17 14:04:00的发言:
lst.Items.Add(dr("Name") & "(" & dr("机构") & ")")
加上以后,麻烦来了,更改用户时出现问题了,因为修改用户打开时首先判断列表中有没有选择用户,如果选择了,那么会去判断,这时就出现了找不到用户的提示,
之前没想到这一点,这个地方怎么处理一下?谢谢
Dim UserName As String
Dim UserGroup As String
Dim PassWord As String
Dim UserRoles As String
Dim Usercodes As String
Dim cmd As New SQLCommand
Dim dt As DataTable
If Forms("用户管理").Opened Then
UserName = Forms("用户管理").Controls("ListBox1").SelectedItem
Else
UserName = _UserName
e.Form.Controls("UserName").Enabled = False
e.Form.Controls("UserGroup").Enabled = False
e.Form.Controls("UserRoles").Enabled = False
e.Form.Controls("Usercodes").Enabled = False
End If
e.Form.Text = e.Form.Text & "-" & UserName
cmd.C
cmd.CommandText = "Select * From {Users} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
If dt.DataRows.Count = 1 Then
e.Form.Controls("UserName").Value = UserName
e.Form.Controls("UserGroup").Value = dt.DataRows(0)("Group")
e.Form.Controls("PassWord").Value = dt.DataRows(0)("PassWord")
e.Form.Controls("UserRoles").Value = dt.DataRows(0)("Roles")
e.Form.Controls("Usercodes").value = dt.DataRows(0)("usercodes")
Else
MessageBox.Show("用户不存在或者已经被删除!","提示",MessageBoxButtons.OK)
e.Form.Close()
End If