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.

3
  • Where did you declare and instantiate con? Commented Feb 14, 2013 at 12:05
  • and where did you declare Session("Pid") ? Commented Feb 14, 2013 at 12:05
  • You should print your stack trace here as it will help to know exactly where the exception is being thrown from. Commented Feb 14, 2013 at 12:21

2 Answers 2

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 
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.