给个例子:
'n是窗体类定义变量,判断登陆不成功次数
dim dln as string
dln = Trim(TextBox1.Text)
If dln = "" Then
MessageBox.Show("用户代码不能为空。", "提示", MessageBoxButtons.OK)
Return
End If
Dim p As Integer
p = InStr(dln, "'")
If p > 0 Then
MessageBox.Show("用户名不能包括字符'", "提示")
Return
End If
p = InStr(dln, ";")
If p > 0 Then
MessageBox.Show("用户名不能包括字符;", "提示")
Return
End If
Dim flg As Boolean = False '登陆是否成功
'取数据表
Dim sqlda As New SqlClient.SqlDataAdapter
Dim sqlcom As New SqlClient.SqlCommand
Dim ds_t As New DataSet
sqlcom.Connection = Sqlconn1
sqlcom.CommandText = "select per_name,dept_name,per_pass from person where per_login='是' and per_code='" + dln + "'"
sqlda.SelectCommand = sqlcom
sqlda.Fill(ds_t, "person")
If ds_t.Tables(0).Rows.Count = 1 Then
If Not IsDBNull(ds_t.Tables(0).Rows(0)("per_pass")) Then
If Trim(ds_t.Tables(0).Rows(0)("per_pass")) = Trim(TextBox2.Text) Then
flg = True ‘密码正确
dlm = Trim(ds_t.Tables(0).Rows(0)("per_name"))
dldept = Trim(ds_t.Tables(0).Rows(0)("dept_name"))
End If
End If
End If
Cursor = Cursors.Default
If flg Then
Close()
Else
n = n + 1
If n = 3 Then
MessageBox.Show("用户已达到最大尝试次数,系统将退出。", "提示", MessageBoxButtons.OK)
Call Button2_Click(sender, e)
Else
MessageBox.Show("用户密码不正确,请重试。", "提示", MessageBoxButtons.OK)
End If
End If