DataTable dt = new DataTable(); dt.Columns.Add("Name"); dt.Columns.Add("Age"); DataRow dr = dt.NewRow(); dr["Name"] = "John"; dr["Age"] = 30; dt.Rows.Add(dr);
using System.Data; DataSet ds = new DataSet(); DataTable dt = ds.Tables.Add("Employees"); dt.Columns.Add("Name"); dt.Columns.Add("Age"); dt.Rows.Add("John", 30); dt.Rows.Add("Sarah", 28); dt.Rows.Add("Michael", 35);In this example, we create a new DataSet and add a new DataTable named Employees. We then add two columns - Name and Age. Finally, we add three new rows to the data table using the Rows.Add method and passing in the values for each column. Package library: System.Data.