我有一個gridview,它顯示了在頁面加載事件中我已經預訂他們的票的乘客的細節 我有以下代碼。如何在asp.net中使用vb創建會話
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
我收到此錯誤: System.NullReferenceException: Object reference not set to an instance of an object.
你在哪裏聲明和實例化了con? – Tobsey 2013-02-14 12:05:26
你在哪裏申報Session(「Pid」)? – futile 2013-02-14 12:05:58
您應該在這裏打印您的堆棧跟蹤,因爲它有助於準確瞭解拋出異常的位置。 – gaurav 2013-02-14 12:21:00