首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请帮忙小弟我分析VB 2010 代码有关问题?

2013-11-08 
请帮忙我分析VB 2010 代码问题??Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As S

请帮忙我分析VB 2010 代码问题??
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim i As Integer

       
        username = Me.cbouser.Text
        password = txtpassword.Text
        Dim myconnection As New OleDbConnection("Provider=sqloledb.1;user id=sa;password=a;initial catalog=zywy;date source=txlgl")
        Dim mycommand As OleDbCommand
        Dim mydatareader As OleDbDataReader
        Dim s As String = "select * from txlgl where xingming='" & Trim(username).Replace("'", "''") & "' and mima='" & Trim(password).Replace("'", "''") & "'"
        myconnection.Open()
        mycommand = New OleDbCommand(s, myconnection)
        mydatareader = mycommand.ExecuteReader()
        If mydatareader.Read = False Then
            MsgBox("用户名不存在或者密码错误", 0 + 48, "提示")
            username = ""

            i = i + 1

            If i > 2 Then '判断输入用户名和密码错误的次数是否大于3次
                MsgBox("您输入用户名和密码错误已经超过三次,您无权登录此系统!", MsgBoxStyle.Exclamation, "信息框")
                Me.Close() '退出系统
            End If
        Else
            frm_main.Show()

            Me.Hide()


        End If
        '  mydatareader.Close()
        '  myconnection.Close()



    End Sub

我通过添加监视 i ,发现i 一开始是0,然后通过i=i+1后,变成了1,然后我准备输第二次用户之前,i又变成0,为什么???一直不能执行语句
 If i > 2 Then '判断输入用户名和密码错误的次数是否大于3次
                MsgBox("您输入用户名和密码错误已经超过三次,您无权登录此系统!", MsgBoxStyle.Exclamation, "信息框")
                Me.Close() '退出系统
            End If
请问为什么???
[解决办法]
Dim i As Integer
这个叫局部变量,在每次调用的时候都是独立的。

你得写在方法的外面
Private i As Integer

热点排行