版权声明: https://blog.csdn.net/eds124/article/details/86034157
Partial Class Root_Login
Inherits System.Web.UI.Page
Protected Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate
Dim rootname As String = Me.Login1.UserName.Trim().ToLower() '获取用户名
Dim rootpass As String = Me.Login1.Password.Trim().ToLower() '获取密码
Dim sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=mydata;User ID=sa;Password=Abcdefg1", "select count(*) from t_root where rootname = @rootname and rootpass = @rootpass")
sds.SelectParameters.Add("rootname", rootname)
sds.SelectParameters.Add("rootpass", rootpass)
Dim pc As IEnumerable = sds.Select(DataSourceSelectArguments.Empty) '执行查询
Dim dv As Data.DataView = CType(pc, Data.DataView) '转换成DataView
Dim o As Object = dv(0)(0) '取出第一行第一列
Dim s As String = o.ToString() '转成字符串
If s.Equals("0") Then
Response.Write("管理员名或密码错误")
Return
End If
Session("username") = rootname
Session("userpass") = rootpass
Response.Redirect("~/Root/Default.aspx") '跳转
End Sub
End Class