DataTable dataTable = new DataTable(); DataRow row = dataTable.NewRow(); row["Column1"] = "Value1"; row["Column2"] = "Value2"; dataTable.Rows.Add(row);
DataTable dataTable = new DataTable(); for (int i = 0; i < 5; i++) { DataRow row = dataTable.NewRow(); row["Column1"] = "Value" + i; row["Column2"] = i; dataTable.Rows.Add(row); }This code creates a new DataTable object, loops through five iterations and creates new DataRow objects using the NewRow method in each iteration. It sets the values of two columns in each row and adds the rows to the DataTable. Package library: System.Data.dll Overall, the System.NewRow method is a useful tool for adding new rows to a DataTable in C#. It simplifies the process of creating new rows and ensures that the schema of the row matches with the DataTable. It is part of the System.Data namespace which is included in the System.Data.dll package library.