Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using LINQ query to update a DataTable. Is their any possibility to get the number of rows affected while executing the query? following is the query i was using, it works fine at all but i have to take the count of rows affected.
C#
dataTable.Select(string.Format("[rollNumber]>'{0}'", 10))
        .ToList<DataRow>()
        .ForEach(r =>
        {
            r["Sem"] = 6;          
        });
Posted
Updated 24-Feb-15 18:24pm
v2

The List that you're creating "in the middle" of your statement "knows" the number of records. You can simply do it in two steps and get the number of records inbetween:
C#
var rows = dataTable.Select(string.Format("[rollNumber]>'{0}'", 10)).ToList<DataRow>();
int numberOfRecords = rows.Count;
rows.ForEach(r =>
        {
            r["Sem"] = 6;
        });
 
Share this answer
 
Comments
BillWoodruff 25-Feb-15 0:45am    
+5
[no name] 25-Feb-15 0:51am    
merci
First make a copy for that data table before update say dt1
after update you will get another table say dt2

Now you can write below code

dt1.Merge(dt2);

DataTable d3 = dt2.GetChanges();

return d3.Rows.Count;
 
Share this answer
 
use below command

System.Data.Linq.ChangeSet changes = db.GetChangeSet();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900