Friday, January 8, 2010

How to add a new row in DataTable?

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

}

No comments:

Post a Comment