How to add a new row in DataTable?

 Posted by Raja on 6/7/2009 | Category: ADO.NET Interview questions | Views: 18963
Answer:

To add a new row in DataTable, we can use NewRow() method of the DataTable object.(Here assume that there are two columns Name, Address in the DataTable.


DataTable dTable = new DataTable();
DataRow row = null;

for (int i = 0; i < 5; i++)
{
row = dTable.NewRow ();
row["Name"] = i + " - Raja";
row["Address"] = "USA";
dTable.Rows.Add(row);
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response