Foxtable(狐表)用户栏目专家坐堂 → 自定义用户的登录判断


  共有7852人关注过本帖树形打印复制链接

主题:自定义用户的登录判断

帅哥哟,离线,有人找我吗?
jaegea
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3832 威望:0 精华:0 注册:2011/5/31 15:45:00
自定义用户的登录判断  发帖心情 Post By:2012/4/21 17:46:00 [只看该作者]

自定义用户管理中,在用户登录的“确定”按钮中,怎样在登录之前进行对输入的用户名的判断,如无此用户名返回一个信息提示,以下代码只能是判断空值,如果输入的不是空值,但用户表中无此用户名的话就会出现程序错误。说明一下,输入框必须支持手工输入的。

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim
cmd As New SQLCommand
Dim
dt As DataTable
Dim
dr As DataRow
cmd.ConnectionName =
"User"
If
UserName = "" Then
    Messagebox.show(
"请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End
If
cmd.CommandText =
"Select * From {Users} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(
0)
If
e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr(
"Group")
    e.Form.Close

Else

    Messagebox.show(
"密码错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If


 回到顶部
帅哥哟,离线,有人找我吗?
blackzhu
  2楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57596 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2012/4/21 18:04:00 [只看该作者]

那你在输入的时候判断一下呗.

 回到顶部
帅哥哟,离线,有人找我吗?
jaegea
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3832 威望:0 精华:0 注册:2011/5/31 15:45:00
  发帖心情 Post By:2012/4/22 12:43:00 [只看该作者]

图片点击可在新窗口打开查看就是不知道怎么判断才问呀

 回到顶部
帅哥哟,离线,有人找我吗?
布莱克朱
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:623 积分:3897 威望:0 精华:0 注册:2011/8/3 22:13:00
  发帖心情 Post By:2012/4/22 19:50:00 [只看该作者]

怎么判断,上面的代码就可以用的呀,你把事件位置动动就可以了.

 回到顶部
帅哥哟,离线,有人找我吗?
jaegea
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3832 威望:0 精华:0 注册:2011/5/31 15:45:00
  发帖心情 Post By:2012/4/23 11:57:00 [只看该作者]

已經搞定,不是移什麼位置,是要再加一個判斷

 

Dim UserName As String = e.Form.Controls("UserName").Value
Dim
cmd As New SQLCommand
Dim
dt As DataTable
Dim
dr As DataRow
cmd.ConnectionName =
"User"
If
UserName = "" Then
    Messagebox.show(
"请选择用户!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End
If

 

Dim dr2 As DataRow 
dr2 = DataTables("用戶表").Find("[用戶] = '" & UserName & "'")
If dr2 IsNot Nothing Then


cmd.CommandText =
"Select * From {Users} Where [Name] = '" & UserName & "'"
dt = cmd.ExecuteReader
dr = dt.DataRows(
0)
If
e.Form.Controls("PassWord").Value = dr("Password") Then
    _UserName = UserName
    _UserGroup = dr(
"Group")
    e.Form.Close

Else

    Messagebox.show(
"密码错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

Else
    Messagebox.show(
"用戶名错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

 

[此贴子已经被作者于2012-4-23 11:57:39编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
blackzhu
  6楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 一级勋章
等级:狐仙 帖子:9875 积分:57596 威望:0 精华:15 注册:2008/9/1 9:45:00
  发帖心情 Post By:2012/4/23 12:15:00 [只看该作者]

呵呵,不做解释,如果这样,意义就不大了.

 回到顶部