Maharshi
Maharshi

Reputation: 1198

Datatable select length of row value for double

I know how to filter or select from datatable in C# as following. (If datatype of the column is string). Like following

Bool ReturnValue = DataTable.Select("LEN([" + ColumnName + "]) > 5").any();

Above code, if any of the rows containing value has length greater than 50 characters then it will give output as true.

I want to do something like above with double type. Here I have column "columnName" which is of double datatype. In this case above code will give me an error.

Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.

Because LEN() is not applicable for double type. Anyone know how to do the same for double datatype column. E.g.

Correct: "abcdef"
Error: "123456"

Because first one is of string type and LEN() is applicable to it but not applicable for second case. because all are numbers there so the datatype of the column in datatable is double or int32 and LEN() doesn't work there.

Pls help Thanks

Upvotes: 1

Views: 4478

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236218

You can use LINQ to DataSet:

DataTable.AsEnumerable().Any(r => r.Field<double>(ColumnName).ToString().Length > 5)

But calculating 'length' of double is very strange. E.g. 10 will have length equal 2, but 1.2345 will have length equal to 6

Upvotes: 2

Related Questions