Click here to Skip to main content
15,907,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to add datatable into the session
Posted
Comments
Kenneth Haugland 23-Mar-13 11:02am    
DataTable dt = new Datatable; ?
[no name] 23-Mar-13 11:18am    
DataTable dt = new Datatable(); :-)
Kenneth Haugland 23-Mar-13 11:22am    
Ah, forgoth about (), not really used to C# :-)

1 solution

Take a look at this example: C# DataTable[^]

C#
/// <summary>
    /// This example method generates a DataTable.
    /// </summary>
    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;
    }
}
 
Share this answer
 
v2

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