asp.net中sqldatareader中的问题!
为什么会同一段代码会出现两种情况,我先发代码,然后再说说会出现什么问题吧。登录按钮:
Dim sqlconn As New SqlConnection
Dim sqlcomm As New SqlCommand
sqlconn.ConnectionString = "workstation id=SS24202;packet size=4096;user id=sa;data source=SS24202;persist security info=False;initial catalog=WebSta"
sqlconn.Open()
sqlcomm.Connection = sqlconn
sqlcomm.CommandType = CommandType.Text
SqlComm.CommandText = "select * from Table_Login where Log_User='" & TBName.Text & "' and Log_password='" & TBPW.Text & "'"
Dim reder As SqlClient.SqlDataReader
reder = SqlComm.ExecuteReader
If reder.Read Then
SqlConn.Close()
SqlConn.Open()
Response.Write("<script language='javascript'>alert('登录成功!')</script>")
sqlconn.Close()
Session("user") = TBName.Text
LabInfo.Text = "欢迎您回来! " & Session("user")
Session.Timeout = 30
Panel1.Visible = False
Panel2.Visible = True
Else
SqlConn.Close()
Response.Write("<script language='javascript'>alert('帐号或密码错误,请重新输入!')</script>")
End If
检查用户名按钮:
Dim sqlconn As New SqlConnection
Dim sqlcomm As New SqlCommand
sqlconn.ConnectionString = "workstation id=SS24202;packet size=4096;user id=sa;data source=SS24202;persist security info=False;initial catalog=WebSta"
sqlconn.Open()
sqlcomm.Connection = sqlconn
sqlcomm.CommandType = CommandType.Text
sqlcomm.CommandText = "select * from Table_Login where Log_User ='" & TBName.Text & "'"
Dim reder As SqlDataReader
reder = sqlcomm.ExecuteReader()
If reder.Read Then
sqlconn.Close()
Response.Write("<script language='javascript'>alert('用户名已存在')</script>")
Else
sqlconn.Close()
Response.Write("<script language='javascript'>alert('用户名不存在')</script>")
End If
登录按钮可以出现密码错误就弹出提示,但检查用户名的按钮,不管你数据库里面有没有记录,它都只会弹出第二个用户名不存在的提示。这是什么原因,请高手指教。
补充:.NET技术 , ASP.NET