6

The error is shown at select when i write next LINQ query:

DataTable dtbl = //...
int count = (from p in dtbl select p.RecordID).Max();

please help me out.

2 Answers 2

3

Try this.

int count = dtbl.Max(p => p.RecordID);

Edit:

You can't easily use Linq on a DataTable.

See: LINQ query on a DataTable

Sign up to request clarification or add additional context in comments.

6 Comments

isn't that just rewriting it :D?
@The_Butcher: It is and is better
@The_Butcher - no its not rewriting it. Its fixing the intention.
dtbl is a datatable. it is giving error "'System.Data.DataTable' does not contain a definition for 'Max' and no extension method 'Max' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?)" when i add this line.
Try dtbl.AsEnumerable().Max(p => p.RecordID);
|
0

According to your comment that dtbl is a DataTable you can do:

int count = dtbl.AsEnumerable().Max(r => r.Field<int>("RecordID"));

You will need to add a reference to System.Data.DataSetExtensions.dll and add a using System.Data directive to the source file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.