最简单Login程序

代码
 Protected Sub btnLogon_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnLogon.Click

        
If Page.IsValid Then

            
Dim SQL As String = "Select pwd ,username from sys_user where username=@uid "
            
Dim myconnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connstring"))
            
Dim mycommand As SqlCommand = New SqlCommand(SQL, myconnection)
            myconnection.Open()
            mycommand.Parameters.Add(
"@uid", SqlDbType.Char).Value = Trim(txtUserName.Text)
            mycommand.Parameters.Add(
"@pwd", SqlDbType.Char).Value = Trim(txtPwd.Text)
            
Dim myreader As SqlDataReader = mycommand.ExecuteReader

            
If myreader.Read Then
               
                
Dim mdString As String = Trim(txtPwd.Text)

                
If mdString = Trim(myreader.GetValue(0)) Then
               
                    myreader.Close()
                    myreader 
= Nothing
                    myconnection.Close()
                    myconnection 
= Nothing
                    Response.Redirect(
"index.html")

                
Else
                    myreader.Close()
                    myreader 
= Nothing
                    myconnection.Close()
                    myconnection 
= Nothing
                    Response.Write(
"<script language='javascript'>alert('对不起,用户或密码错误!!');</script>")
                
End If
            
Else
                Response.Write(
"<script language='javascript'>alert('对不起,没有此用户');</script>")
            
End If
        
End If


    
End Sub
原文地址:https://www.cnblogs.com/callbin/p/1620450.html