How to Update Data table Using Linq
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Address", typeof(string));
dt.Columns.Add("Salary", typeof(int));
dt.Columns.Add("Status", typeof(int));
dt.Columns.Add("DateOFName", typeof(DateTime));
DataRow dr = dt.NewRow();
dr["Id"] = 1;
dr["Name"] = "Umesh";
dr["Address"] = "Kolhapur";
dr["Salary"] = 32000;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Id"] = 2;
dr["Name"] = "mahesh";
dr["Address"] = "Pune";
dr["Salary"] = 15000;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Id"] = 3;
dr["Name"] = "Vinayak";
dr["Address"] = "Kolhapur";
dr["Salary"] = 18000;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Id"] = 4;
dr["Name"] = "Sagar";
dr["Address"] = "Mumbai";
dr["Salary"] = 25000;
dt.Rows.Add(dr);
This code is working............
IEnumerable<DataRow> rows1 = dt.Select("Id>2 and name not like '%s%'");
rows1.ToList().ForEach(r => r.SetField("Name", "AnotherName"))
if i change into one line ,then it no work
IEnumerable<DataRow> rows1 = dt.Select("Id>2 and name not like '%s%'").ToList().ForEach(r => r.SetField("Name", "AnotherName"))