Some times we have a need to store values temporarily. In Every time of process we can't store the values to SQL or MS access database. So to access temporary values we using data table in c#. The data table gives the convenient way to store the data in memory.Creation of data table:The syntax of the Datatable creation isDatatable datatablename =new Datatable ();Example:Datatable dt =new Datatable ();Here dt is a Datatable name and new represents creating a new Datatable with null value.Add column:To add a new column in Data table we using below syntaxdt.Columns.Add ("Columname"); Example:dt.Columns.Add ("Name");Here we created a "Name" column in Datatable dt.Add Row and item:Syntax of add row, datatablename.Rows.Add(); DataRow datarowname; datarowname =datatablename.NewRow(); datarowname["columnname"] = object; datatablename.Rows.Add(datarowname);Example: dt.Rows.Add(); DataRow dr; dr = dt.NewRow(); dr["Name"] = "aaa"; dt.Rows.Add(dr);Delete Row:Syntax for deletion:datatablename.Rows [Rowvalue].Delete ();datatablename.RemoveAt (Rowvalue);Exampledt.Rows [0].Delete ();dt.Rows.RemoveAt (0);
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: