score:14
Accepted answer
Use this line in your query:
where row.Field<decimal?>("ParentID") == rootid
decimal?
is syntactic sugar for System.Nullable<decimal>
, which is essentially the same as decimal
, except that it also allows for null
values.
long
is a different type altogether -- it can only represent integers and not decimal values, hence the "Specified cast is not valid" error.
score:0
long rootid is nullable type? It should be then only it can accept nulls
Source: stackoverflow.com
Related Articles
- Linq to DataTable - Cannot cast DBNull
- Object cannot be cast from DBNull to other types Linq
- Object cannot be cast from DBNull to other types in linq expression
- LINQ Source Code Available
- Cannot convert source type to target type List<KeyValuePair> Linq
- Cannot cast from generic to get LINQ where clause
- creating Linq to sqlite dbml from DbLinq source code
- Cannot Cast String to GUID in LINQ to Entities
- CLRSQL Aggregate function. LINQ Code works within CLR Function but cannot be deploy within Aggregate
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- source code for LINQ 101 samples
- Get a list of all DBNull cells of a DataTable with Linq
- Cannot convert source type 'System Linq IQueryable<decimal>' to target type decimal
- Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type. on using Linq Query
- LINQ CopyToDataTable -- Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type
- c# Linq or code to extract groups from a single list of source data
- Cast ITable to IEnuerable<object> - Dynamic LINQ to SQL Query with no DataTable information
- Getting error "Object cannot be cast from DBNull to other types"
- Querying Datatable DBNull using Linq Query
- Unable to cast object of type grouping to datarow after i grouped datatable with linq
- Entity Framework Code First - The entity or complex type cannot be constructed in a LINQ to Entities query
- LINQ query on a DataTable
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Value cannot be null. Parameter name: source
- Filling a DataSet or a DataTable from a LINQ query result set
- LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
- Linq code to select one item
- Cast LINQ result to ObservableCollection
- How are people unit testing code that uses Linq to SQL
- Using distinct on a column while getting multiple column data
- How to Convert this Linq Query into Lambda Expression
- How do I override the Contains method of IQueryable during a unit test?
- how to cast object of type '<TakeIterator>[System.Data.DataView]' to type 'System.Data.DataView'.?
- More elegant way to get the next meeting date
- C# - How to Filter a List for condition A, then for these matched only, Filter by Condition B, without breaking the List Order
- How can i improve this with linq?
- Performance difference between `is` and `as` in LINQ
- How to perform 2 checks in LINQ Where
- In group by elements, select value different from null in other column
- Orderby() not ordering numbers correctly c#
- Linq query to count field in datatable
- Convert SQL query with inner, left, and nested select to LINQ
- Split list into two lists with single LINQ statement
- Data binding access in xaml vs in code behind - Linq to XML?
- How to create more accurate searching?
- Optimizing Linq
- Use view model property to populate drop down list for
- Assigning rows evenly from table
- Trouble converting simple SQL to Linq