-- 作者:ruan
-- 发布时间:2012/2/3 13:05:00
-- 自定义用户 增加用户出错
参考帮助 做的自定义用户管理 在增加用户时候 当已有重复用户的时候会报错~
怎么解决
代码如下
Dim UserName As String = e.Form.Controls("UserName").Value Dim UserGroup As String = e.Form.Controls("UserGroup").Value Dim PassWord As String = e.Form.Controls("PassWord").Value Dim Department As String = e.Form.Controls("Department").Value Dim cmd As New SQLCommand cmd.C If UserName = "" OrElse UserGroup = "" OrElse PassWord= "" Then Messagebox.show("请输入帐号名,密码和用户分组!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Return End If cmd.CommandText = "Insert Into {Users} ([Name],[Group],[Password],[Department]) Values (\'" cmd.CommandText = cmd.CommandText & UserName & "\',\'" & UserGroup & "\',\'" & Password & "\',\'" & Department & "\')" If cmd.ExecuteNonQuery = 1 Then \'返回1表示增加成功 Dim Result As DialogResult Result = MessageBox.Show("增加用户成功!是否继续增加", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If Result = DialogResult.Yes Then Else If Forms("用户管理").Opened Then With Forms("用户管理").Controls("ListBox1") .Items.Add(UserName) .SelectedIndex = .Items.Count -1 End With End If e.Form.Close() End If Else Messagebox.show("增加用户失败, 可能存在同名用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) End If 此主题相关图片如下:qq截图20120203125903.jpg
|