Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,


C#
String GrossPrem = "5000";
String OtherPrem = "100";
int i_id = 1;
DataTable Installment = SomeDataTable;

Installment.AsEnumerable().Where(x => x.Field<string>("PayNo").ToString().Equals(i_id.ToString())).FirstOrDefault<DataRow>
(t => t.Field<string>("GrossPrem") = GrossPrem,
                t.Field<string>("OtherPrem") = OtherPrem,
                t.Field<string>("DueDate") = "05/21/2014").AcceptChanges();


I am new to use linq query.

Here i want to update table data using linq
but i get error.

please help me to resolve.

Thanks In Advance
Posted
Comments
joshrduncan2012 21-May-14 10:16am    
It would help if you told us where the error was pointing to and what the text of the error is. We can't read your mind.

possibly you get a compile error because of FirstOrDefault extension method. It has two forms:

either:
XML
public static TSource FirstOrDefault<TSource>(
    this IEnumerable<TSource> source
)


or
XML
public static TSource FirstOrDefault<TSource>(
    this IEnumerable<TSource> source,
    Func<TSource, bool> predicate
)


First version, simply selects a value from a given IEnumerable. The second one needs a selector function. Your usage doesn't match any of these two. Therefore, a compile error.

Since you don't know how to use it I advice you to check out some samples on msdn and other sites.

documentation is here:
FirstOrDefault[^]

another advice is to use typed datasets and tables. use the designer of the IDE to create your data structures.
see here: create dataset[^]

and a good start point for linq: LINQ[^]

If you follow instructions on these pages, you can have deeper understanding of those concepts and tools.

have a good day.
 
Share this answer
 
SQL
dtNewLCM.AsEnumerable().Where(row => row.Field<string>("leafClass")=="0")
    .Select(b => b["leafClass"] = "MyValue1.")
    .ToList();
 
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