以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  出现超出数组范围提示怎么回事?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=16227)

--  作者:zcw2764
--  发布时间:2012/2/6 14:48:00
--  出现超出数组范围提示怎么回事?
出现超出数组范围提示怎么回事?
--  作者:zcw2764
--  发布时间:2012/2/6 14:52:00
--  

Dim Name As String = e.Form.Controls("Name").Value
Dim cmd As New SQLCommand
Dim dt As DataTable
Dim dr As DataRow
cmd.C
If Name = "" Then
    Messagebox.show("请选择或输入用户登录名!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
End If
cmd.CommandText = "Select * From {用户} Where [登录名] = \'" & Name & "\'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)
If dt.DataRows.Count = 0 Then \'返回1表示更改成功
    Messagebox.show("用户名输入错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
    Return
Else
    If  dr("禁用") = True Then
        Messagebox.show("此用户已禁用,请与管理员联系!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Return
    Else
        If e.Form.Controls("PassWord").Value = dr("密码") Then
            _Name = Name
            _UserName = dr("用户名")
            _UserGroup = dr("用户组")
            _UserJS = dr("角色")
            e.Form.Close
        Else
            Messagebox.show("密码错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        End If
    End If

登录时输入的用户名不在用户表中,确定时出现“超出数组范围”的错误提示


--  作者:狐狸爸爸
--  发布时间:2012/2/6 14:58:00
--  

cmd.CommandText = "Select * From {用户} Where [登录名] = \'" & Name & "\'"
dt = cmd.ExecuteReader
dr = dt.DataRows(0)

改为:

 

 

cmd.CommandText = "Select * From {用户} Where [登录名] = \'" & Name & "\'"
dt = cmd.ExecuteReader
if  dt.Datarows.Count = 0 then

    Messagebox.show("用户名错误!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

    return

End if

dr = dt.DataRows(0)


--  作者:zcw2764
--  发布时间:2012/2/6 15:09:00
--  
已解决,谢谢