You must Sign In to post a response.
  • Category: LINQ

    How to Update Data table Using Linq


    Are you looking for a way to update Data table Using Linq ? then read this thread to know how to update it



    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);


    IEnumerable<DataRow> rows1 = dt.Select("Id>2 and name not like '%s%'");
    rows1.ToList().ForEach(r => r.SetField("Name", "AnotherName"))
  • #742233
    Hi,

    You can post these code in Articles / code snippets Section , AS i understand this is not a problem and you are trying ti give the code for
    How to Update Data table Using Linq

  • #742236
    Can you please provide the issue you are facing for the same.???
    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments