【问题标题】:how to create session in asp.net using vb如何使用 vb 在 asp.net 中创建会话
【发布时间】: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") ?
  • 你应该在这里打印你的堆栈跟踪,因为它有助于准确地知道异常是从哪里抛出的。

标签: asp.net vb.net


【解决方案1】:

会话Session("Pid") 为空,你应该用之前的数据填充它,你还应该检查会话:

If Session("Pid") IsNot Nothing Then
' write your code
End If 

【讨论】:

    【解决方案2】:

    在使用之前检查你所有的“SESSIONS”是否为空............

    还有Refer

    还有IRequiresSessionState Interface

    指定目标 HTTP 处理程序需要对会话状态值进行读写访问。这是一个标记接口,没有方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      相关资源
      最近更新 更多