【问题标题】:session variable- data table null value- asp.net C#会话变量-数据表空值-asp.net C#
【发布时间】:2017-05-18 11:22:43
【问题描述】:

我似乎无法确定为什么我的会话变量在打印项单击事件中返回 null。数据表出现在会话变量之前。

感谢任何建议。

    protected void btnGetOrderData_Click(object sender, EventArgs e)
    {
        Class1 x = new Class1(); // create a new instance of class1

        x.sopnumbe = txtOrder.Text; // pass the class string the value of text box order 

        DataSet ds = x.GetOrderData(); // call get order from class1 "x" instance 

        DataTable orderDataTable = ds.Tables[0]; // dataset to datatable (first)

        Session["sess_dt"] = orderDataTable; // create a session var to store dataset and use elsewhere


        //  GridView1.DataSource = ds;
        //  GridView1.DataBind();

    }

    protected void btnPrintItem_Click(object sender, EventArgs e)
    {

        DataTable dt = (DataTable)Session["sess_dt"];

【问题讨论】:

    标签: c# asp.net session-variables


    【解决方案1】:

    存储:

     DataTable dt = new DataTable();
     Session["sess_dt"] = orderDataTable; 
    

    检索:

     DataTable dt = (DataTable)Session["sess_dt"];
    

    检查您的orderDataTable 是否有值。

    【讨论】:

    • 是的。它在那个时候是有价值的。在最后一行检索后为空。我希望有人知道为什么。
    • 如果是null,演员表会失败。
    • 也许您在将会话转换为 DataTable 时遇到问题?尝试使用这个:DataTable dt = Session["sess_dt"] as DataTable
    猜你喜欢
    • 1970-01-01
    • 2018-09-21
    • 2015-03-11
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    相关资源
    最近更新 更多