简体   繁体   中英

how to create session in asp.net using vb

I have a gridview which shows the details of passenger who have booked their ticket on page load event i have following code.

Label1.Text = Session("Pid").ToString()
    Dim Sql As String = "select * from Plist where Pid='" & Label1.Text & "'"
    Try
        con.ConnectionString = strCon
        Dim cm As New SqlClient.SqlCommand(Sql, con)
        con.Open()
        cm.ExecuteNonQuery()
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        If con.State = ConnectionState.Open Then
            con.Close()

        End If
    End Try

I am getting this error: System.NullReferenceException: Object reference not set to an instance of an object.

the session Session("Pid") is null, you should fill it with data before and you also should check the session:

If Session("Pid") IsNot Nothing Then
' write your code
End If 

Check all your "SESSIONS" for null before using it...................

And Refer

and also IRequiresSessionState Interface

Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM