| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 865 人关注过本帖
标题:vb登录代码出现问题!请指教
只看楼主 加入收藏
zhx790503
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-30
收藏
 问题点数:0 回复次数:1 
vb登录代码出现问题!请指教
请高手指教!关于登录代码,我运行的时候如果用户名和密码输入正确的话,就没问题,但是如果输错了一次的话,就在也进不去了,即使用户名,密码都正确,不知道怎么回事,有人知道吗?以下是代码登录:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'数据库连接
Dim conn As New SqlClient.SqlConnection
'conn的连接字符串在下边的case语句中进行定义
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = conn
'定义变量
Dim strpassword As String
Dim strRealPw As String
Dim strTableName As String = DropDownList1.SelectedItem.value '用户登陆表名
Dim strID As String '用户ID字符串
Dim str_PW As String '用户密码字符串
Dim strPath As String '根据用户身份登陆字符串
Dim strUserIdent As String '用户身份标识
Dim bool1 As Boolean = False '判断是否通过验证
Dim strupdate As String '更新语句
Dim str_iflogin As String


'数据库查询语句---在此处添加语句--对用户分类——设置用户ID字符串
Dim flag As Boolean = True

Select Case strTableName
Case "student_login"
conn.ConnectionString = ConfigurationSettings.AppSettings("DSN_student")
strID = "S_ID"
str_PW = "SL_pwd"
'str_iflogin = "sl_if"
strPath = "../network_course/student/index.aspx"
strUserIdent = "同学"
Case "teacher_login"
conn.ConnectionString = ConfigurationSettings.AppSettings("DSN_teacher")
strID = "T_ID"
str_PW = "TL_pwd"
'str_iflogin = "tl_if"
strPath = "../network_course/teacher/index.aspx"
strUserIdent = "老师"
End Select

'验证用户ID和密码
cmd.CommandText = "select * from " + strTableName + " where " + strID + "='" & TextBox1.Text & "'" '查询语句
Try
conn.Open()
Dim reader As IDataReader
reader = cmd.ExecuteReader()
strpassword = TextBox2.Text
If reader.Read Then
strRealPw = reader.Item(str_PW)

If Trim(strpassword) = Trim(strRealPw) Then '比较密码和输入
'If reader.Item(str_iflogin) = 0 Then
bool1 = True
'Else
' Label4.Text = "此账户已经登录在线!"
'End If
Else
Label4.Text = "密码错误!"
bool1 = False
End If
Else
Label4.Text = "用户名输入错误!"
bool1 = False
End If
reader.Close()
Catch
Label4.Text = "数据库操作失败,可能是服务器出现错误,请稍后再试!非常抱歉影响了您的工作!"
Finally
conn.Close()
strpassword = ""
strRealPw = ""
End Try

If bool1 Then '
'设置cookie参数
Dim userName As String
Dim userIdentity As String
Dim userRealName As String

If (Request.Cookies("userInf")) Is Nothing Then
Dim cookie As HttpCookie = New HttpCookie("userInf") '创建新的cookie
cookie.values.add("userID", TextBox1.Text) '加入用户的账号
cookie.values.add("userIdent", strUserIdent)
Response.AppendCookie(cookie)
Else
Dim cookie As HttpCookie = New HttpCookie("userInf")
cookie.values("userID") = TextBox1.Text
cookie.values("userIdent") = strUserIdent
Response.AppendCookie(cookie)
End If

Response.Redirect(strPath) '进入到主页面

End If
End Sub
End Class

搜索更多相关主题的帖子: 数据库 代码 New 指教 cmd 
2006-05-30 16:12
oヤ偽妳變壞
Rank: 2
等 级:新手上路
威 望:4
帖 子:2251
专家分:0
注 册:2006-3-19
收藏
得分:0 
2006-05-30 16:47
快速回复:vb登录代码出现问题!请指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.059138 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved