如何用vb在asp.net中创建会话 [英] how to create session in asp.net using vb

查看:84
本文介绍了如何用vb在asp.net中创建会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,显示谁已预订机票的乘客的详细信息
在页面加载事件我有以下code。

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

我得到这个错误:
System.NullReferenceException:未将对象引用设置到对象的实例

推荐答案

会话会议(PID)为空,你应该在你面前的数据填充它还应检查会话:

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 

这篇关于如何用vb在asp.net中创建会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆