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();