Tutorial :Expression in DataTable


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??


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:

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »