To delete the first row in DataTable

Posted by Amatya under C# category on | Points: 40 | Views : 1664
If I want to delete the First record from DataTable then we can use this code

So here i will create a dataTable
DataTable dt = new DataTable(); 

Now I will add the columns to dataTable of fields Name, Location, Degree
and Date

dt.Columns.Add("Name", typeof(string)); 
dt.Columns.Add("Location", typeof(string));
dt.Columns.Add("Degree", typeof(string));
dt.Columns.Add("Date", typeof(DateTime));

Now adding the rows to the DataTable with meaningful records
dt.Rows.Add("Amatya", "Bangalore", "MCA", DateTime.Now); 
dt.Rows.Add("Aditya", "Bangalore", "BCA",DateTime.Now);
dt.Rows.Add("Shryansh", "Delhi", "MCom", DateTime.Now);

Now if I want to delete the first row from DataTable then we can use the following code


hope it will help u guys


Comments or Responses

Login to post response