【发布时间】:2013-02-14 12:02:39
【问题描述】:
我有一个显示已预订机票的乘客详细信息的网格视图 在页面加载事件中,我有以下代码。
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? -
你在哪里声明 Session("Pid") ?
-
你应该在这里打印你的堆栈跟踪,因为它有助于准确地知道异常是从哪里抛出的。