tags:

views:

10

answers:

1

Hi,

I have this simple code:

    currentDataTable.Columns.Add("Active", Type.GetType("System.Boolean"));
    currentDataTable.Columns.Add("Symbol", Type.GetType("System.String"));
    currentDataTable.PrimaryKey = new DataColumn[] {currentDataTable.Columns[1]};

    string FilterExpression = "Symbol = AAA";
    DataRow[] existingRows = currentDataTable.Select(FilterExpression);

When executing, I get this error: Cannot find column [AAA].

What am I doing wrong??

A: 

If you want "AAA" to be interpreted as a string, use:

string FilterExpression = "Symbol = 'AAA'";

From the DataColumn.Expression documentation:

When you create an expression for a filter, enclose strings with single quotation marks:

Quartermeister