How to add, delete and update rows in Datatable in .Net

We know that the Data Table data type can contains records in table structure.
We can easily understand by the following example that how can we add rows, delete rows and update rows of any Data Table at run time.

[VB.Net]

        ' Declare dataTable
        Dim dtTest As New DataTable
 
        'Add columns
        dtTest.Columns.Add("Name")
        dtTest.Columns.Add("Address")
 
        ' Declare Data Row 
        Dim dr As DataRow
 
        'Assign Data Row of datatable
        dr = dtTest.NewRow()
 
        'Add values in data row columns
        dr("Name") = "John"
        dr("Address") = "Boston"
 
        ' Add Data Row in Data Table
        dtTest.Rows.Add(dr)
 
        ' Update Any column of any row
        dtTest.Rows(0)("Name") = "Jackson"
 
        ' Delete any row of Data Table
        dtTest.Rows(0).Delete()

[C#]

              // Declare dataTable
 
                DataTable dtTest = new DataTable();
 
                //Add columns
                dtTest.Columns.Add("Name");
                dtTest.Columns.Add("Address");
 
                // Declare Data Row 
                DataRow dr = null;
 
                //Assign Data Row of datatable
                dr = dtTest.NewRow();
 
                //Add values in data row columns
                dr["Name"] = "John";
                dr["Address"] = "Boston";
 
                // Add Data Row in Data Table
                dtTest.Rows.Add(dr);
 
                // Update Any column of any row
                dtTest.Rows[0]["Name"] = "Jackson";
 
                // Delete any row of Data Table
                dtTest.Rows[0].Delete();

Author: Ankur

Have worked primarily in the domain of Calling, CRM and direct advertisers services. My technological forte is Microsoft Technologies especially Dot Net (Visual Studio 2003, 2005, 2008, 2010 and 2012) and Microsoft SQL Server 2000,2005 and 2008 R2. My Area of Expertise is in C#. Net, VB.Net, MS-SQL Server, ASP. Net, Silverlight, HTML, XML, Crystal Report, Active Reports, Infragistics, Component Art, ComponeOne, Lead Tools etc.