缺少操作数问题,同时使用 DataView 过滤 DataTable

Missing operand issue, while filtering a DataTable with DataView

我仍然面临 missing operand 问题,即使在使用 String.Format 解决了任何潜在的间距问题之后,我希望了解其中的原因。

以下面的方法为例:

public static DataTable FilterByCategory(DataTable dt)
    {
        string category = "C4";
        DataView view = dt.DefaultView;
        view.RowFilter = string.Format("Info dedicated to Printer LIKE '%{0}%'", category);
        DataTable ds = view.ToTable();
        return ds;
    }

SyntaxErrorException: Missing operand after 'dedicated' operator

PS:“打印机专用信息”是 dt 上的过滤列,我的参考是:DataView RowFilter Syntax [C#]

最佳,

对于名称中包含 space 字符的列,您必须使用方括号 [] :

view.RowFilter = string.Format("[Info dedicated to Printer] LIKE '%{0}%'", category);