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.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
hari
  • 61
  • 1
  • 3

2 Answers2

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

Community
  • 1
  • 1
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
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.

Lee
  • 142,018
  • 20
  • 234
  • 287