ASP.net会话变量aspnetdb登录控件



嗨,我试图携带一个会话变量为我的登录控制,我正在使用传递传递到另一个页面,并显示他们的详细信息。我正在使用aspNetDB。我的用户名被设置为一个整数,因为它连接到另一个显示用户详细信息的数据库表,下面是我的代码:

    Protected Sub Login1_LoggingIn(sender As Object, e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles Login1.LoggingIn
            Session("StaffNo") = Login1.UserName()
        End Sub

代码然后被发送到我的另一个页面,以显示他们的详细信息时,加载在数据网格上,但会话似乎没有携带:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Try
            Dim Staff As String = CType(Session.Item("StaffNo"), String)
            Dim conn As SqlConnection
            Dim cmd As SqlCommand
            Dim cmdstring As String = "SELECT * FROM [User] WHERE studentnum = @StaffNo"
            conn = New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True")
            cmd = New SqlCommand(cmdstring, conn)
            cmd.Parameters.Add("@StaffNo", SqlDbType.Char).Value = Staff
            conn.Open()
            Dim myReader As SqlDataReader
            myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

            GridView1.DataSource = myReader
            GridView1.DataBind()
            conn.Close()
        Catch ex As Exception
            Response.Write("An error has occurred")
        End Try
    End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    Try  
Dim cmdstring As String = "SELECT * FROM [User] WHERE studentnum = '"& Session("StaffNo").ToString & "' "
End Sub

相关内容

  • 没有找到相关文章

最新更新