Adding rows to Datatable using C#.NET
Hi Readers, Today I am going to explain you 2 ways that we can use to add rows to a Data table using C#.NET.
So lets begin:
Adding rows to Datatable using C#.NET
> First of all, add columns to data table using the following lines of code:
DataTable dtEmployee = new DataTable("Employee");
dtEmployee.Columns.Add("ID", typeof(int));
dtEmployee.Columns.Add("NAME", typeof(String));
dtEmployee.Columns.Add("AGE", typeof(int));
dtEmployee.Columns.Add("SALARY", typeof(Decimal));
Add row in datatable in c# |
Adding rows to Datatable using C#.NET
drAddRow["ID"] = 1;
drAddRow["NAME"] = "Rohan Sharma";
drAddRow["AGE"] = 21;
drAddRow["SALARY"] = 15000;
dtEmployee.Rows.Add(drAddRow);
Add row in datatable in c# |
dtEmployee.Rows.Add(2, "Priyanshi Gala", 22, 14000);
Add row in datatable in c# |
That's it!!!
Please comment if you have any query regarding the above coding.
And share with your co-programmers to help them out in coding.
LIKE COMMENT & SHARE
Comments
Post a Comment