Skip to content

Issue with Where Clause for a DataTable - String Works - Integer does not... ? #959

@CDNConsultant

Description

@CDNConsultant

Hello,

I have a bunch of DataTables I need to query dynamically.
I have a GenerateClause function that generates a simple where clause based on the type of column being queried...

For example, a String column might look like (City = "Seattle")
and an Int32 field might look like (Size = 3)

However, the string field where clause works fine - but the Int32 field does not work - and generates an error "Specified Cast is not Valid"

Any thoughts as to what might be causing this error message? I will need to put DataTime, Doubles, DateOnly, etc. where clauses as well as the String and Int32.

Here is the code I am using - where the GenateWhereClause is used to gen the string containing the actual clause...

                DataTable ColumnSelTable = dataSet_DataCleaning.Tables["RemoveByCol"];
                CurrWhereClause = GenerateWhereClause(ColumnSelTable);

                var dynamicQuery = CurrTable.AsEnumerable().AsQueryable();
                var dynamicQuery2 = dynamicQuery.Where(DynLinqConfig, CurrWhereClause).ToList();
                ResultingDataTable = dynamicQuery2.CopyToDataTable();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions