"Missing operand before '=' operator" error in DataTable filtering

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alice123
    New Member
    • Nov 2007
    • 2

    #1

    "Missing operand before '=' operator" error in DataTable filtering

    I have a DataTable with ColumnName: ++CustomerName+ +.
    when i try to filter this DataTable as

    string columnName=Tabl e.Columns["++CustomerName ++"].ToString();
    DataRow[] row = Table.Select(co lumnName + " = 'Alice');

    I am getting the above error.

    I feel that because the column name is containing '+' sign, I am getting this error. If the column name does not contain + sign then the filtering is working fine for me.

    My requirement is to have any number of '+' signs in the column name.

    Please suggest a way out.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I think the problem is because you're doing a silly amount of extra work?
    If you already KNOW the column name, why are you doing that string columnname part?

    Code:
    string columnName=Table.Columns["++CustomerName++"].ToString();
    This should set columnName ="System.Data.D ataColumn" or throw a null reference exception if "++CustomerName ++" is not a column in that table.

    On the chance that I'm wrong and it just sticks the column name back in there, then your issue is this:
    Code:
    DataRow[] row = Table.Select(columnName + " = 'Alice');
    And you should change it to be:
    Code:
    DataRow[] row = Table.Select("["+columnName+"] = 'Alice');

    Comment

    • alice123
      New Member
      • Nov 2007
      • 2

      #3
      Thank you plater. It solved our problem.

      Comment

      Working...