Here , We have to copy the unique rows of column 'CategoryName' from DataTable 'dt_old' to the 'Category' column of DataTable 'dt_Categories' using LINQ.
DataTable dt_Categories = new DataTable();
dt_Categories.Columns.Add("Category", Type.GetType("System.String"));
DataTable dt_old = new DataTable();
dt_old = (DataTable)Session["dt"];
dt_Categories = dt_old.AsEnumerable().Select(row =>
{
DataRow newRow = dt_Categories.NewRow();
newRow["Category"] = row.Field<string>("CategoryName");
return newRow;
}).Distinct(DataRowComparer.Default).CopyToDataTable();
No comments:
Post a Comment