Search code examples
vb.netdatagridviewdatatabledataviewrowfilter

dataview.rowfilter syntax error - missing operand mystery


Weird, weird error. I might just be codeblind, but:

    Dim dtdv As New DataView
    dtdv = dt.DefaultView
    dtdv.RowFilter = "Controller ID = 'PS2USB1'"
    XMLDGV.DataSource = dtdv

produces, at line 3:

Missing operand after 'ID' operator.

dt defined and correct. Column heading correct. Weird. Any ideas?


Solution

  • It looks like you have a white space in the Datatable column header. So, you have to enclose the Column name in the RowFilter within square brackets.

    Dim dtdv As New DataView
    dtdv = dt.DefaultView
    dtdv.RowFilter = "[Controller ID] = 'PS2USB1'"
    XMLDGV.DataSource = dtdv