Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

update datatable via datarow 2nd

$
0
0

Hi list,

I have the following datatable, but do not know how to update dt. I can update events, but my aim is to update dt. Any idea please?

DataTable dt = new DataTable();
            dt.Columns.Add("year", typeof(int));
            dt.Columns.Add("event", typeof(int));
            dt.Columns.Add("lob", typeof(string));
            dt.Columns.Add("loss", typeof(int));
            dt.Rows.Add(1, 1,"s4444", 20);
            dt.Rows.Add(1, 1,"s3333", 34);
            dt.Rows.Add(1, 2, "s4444", 40);
            dt.Rows.Add(1, 4, "s4444", 50);
            dt.Rows.Add(2, 3, "s4444", 344);
            string query = "year=1 and event=1 and lob in ('s1301','s2243')";
            DataTable events = new DataTable();
            events = dt.Select(query).CopyToDataTable();

            foreach (DataRow row in events.Rows)
            {
                row["loss"] = 9999;
            }
            events.AcceptChanges();
            dt.AcceptChanges();   //this dows not work


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>