我想在会话中插入表并返回 [英] i want insert table in the session and return

查看:62
本文介绍了我想在会话中插入表并返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我
我要排
和一张桌子
我想在桌子上添加行
并将表插入会话中
我该怎么办?
最后我要返回会话到表类型

plz help me
i want a row
and a table
i want add row on the table
and insert table into a session
how i do it?
and in last i want return session to a table type

推荐答案

以下方法create table并向其中添加记录

following method create table and add records to it

static DataTable GetTable()
{
//
// Here we create a DataTable with four columns.
//
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));

//
// Here we add five DataRows.
//
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
return table;
}


http://www.dotnetperls.com/datatable [


http://www.dotnetperls.com/datatable[^]

DataTable table = GetTable();


您可以将其作为
添加到会话中


you can add this to session as

Session["MyTable"] = table;


您可以作为
访问它


and you can access it as

if (Session["MyTable"]!=null)
{
    DataTable datatable = (DataTable)Session["MyTable"];
}


这篇关于我想在会话中插入表并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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