Click here to Skip to main content
13,140,742 members (48,757 online)
Rate this:
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 26-Jun-12 10:36am
Awesome answer :) +5 :)
Damith Weerasinghe 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 26 Jun 2012
Copyright © CodeProject, 1999-2017
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