Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

1 solution

following method create table and add records to it

C#
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[^]

C#
DataTable table = GetTable();

you can add this to session as
C#
Session["MyTable"] = table;

and you can access it as
C#
if (Session["MyTable"]!=null)
{
    DataTable datatable = (DataTable)Session["MyTable"];
}
 
Share this answer
 
v2
Comments
Pankaj Nikam 26-Jun-12 10:36am    
Awesome answer :) +5 :)
DamithSL 26-Jun-12 10:41am    
Thanks Pankaj

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900