Reputation: 1
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.
Upvotes: 0
Views: 4359
Reputation: 6079
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.
Upvotes: 0
Reputation: 6159
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
Upvotes: 3