Populate new datatable with results and clean up. The above code was prep work, now we’re going to actually execute the query, and populate a datatable with the results. Unfortunately, there’s no good way to convert a Linq list to a Datatable so we’ll just use.Clone() to clone build the new table schema, and then perform an ImportRow.
Hello, String GrossPrem = ' 5000'; String OtherPrem = ' 100'; int iid = 1; DataTable Installment = SomeDataTable; Installment.AsEnumerable.Where(x = x.Field( ' PayNo').ToString.Equals(iid.ToString)).FirstOrDefault (t = t.Field( ' GrossPrem') = GrossPrem, t.Field( ' OtherPrem') = OtherPrem, t.Field( ' DueDate') = ' ').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. Possibly you get a compile error because of FirstOrDefault extension method. It has two forms: either: public static TSource FirstOrDefault ( this IEnumerable source ) or public static TSource FirstOrDefault ( this IEnumerable source, Func 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: another advice is to use typed datasets and tables. Use the designer of the IDE to create your data structures.
See here: and a good start point for linq: If you follow instructions on these pages, you can have deeper understanding of those concepts and tools. Have a good day. When answering a question please:.
Read the question carefully. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.