0

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.

Prajakta P
  • 1
  • 1
  • 1

2 Answers2

3

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 
Alex
  • 5,971
  • 11
  • 42
  • 80
0

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.

Community
  • 1
  • 1
andy
  • 5,979
  • 2
  • 27
  • 49