Click here to Skip to main content
11,719,185 members (89,238 online)
Rate this: bad
Please Sign up or sign in to vote.
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 26-Jun-12 2:45am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;

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"];
Pankaj Nikam at 26-Jun-12 10:36am
Awesome answer :) +5 :)
Damith Weerasinghe at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 1,734
1 OriginalGriff 690
2 Maciej Los 569
3 Richard MacCutchan 540
4 F-ES Sitecore 510

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 26 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100