C# : Adding a new column in datatable and adding value to it

Here I am sharing how you can add a new column and data to a datatable that already contains data from sql.

try
{
   DataSet DS = GetResultsDS(sql); //Execute query and getting result in DataSet.
    if (DS != "" && DS  != null)
    {                
        DS.Tables[0].Columns.Add("DrillDown", typeof(System.String)); //Adding column of string type
        foreach (DataRow row in DS.Tables[0].Rows)
        {
            row["DrillDown"] = "Value for new column"; // setting value
        }
    }
}
catch (Exception e)
{
    logger.Error(e);
}

Documentation : Microsoft Docs




Your feedbacks are most welcome..