c# - DataView row Filtering -
i have 2 dataview
trying sort, in dgtest1 trying exception of data contains typeid != 25
, in dgtest2 trying show data typeid == 25
.
when step through code throwing error on saying
"cannot interpret token '!' @ position 6".
can show me how use string row filter?
the parameters (data table table, string rowfilter, string sort, dataviewrowstate)
dgtest1.itemssource = new dataview(dttest1, "typeid!= 25", "", dataviewrowstate.currentrows); dgtest2.itemssource = new dataview(dttest1, "typeid == 25", "", dataviewrowstate.currentrows);
the correct syntax use rowfilter expression in first dataview constructor is
dgtest1.itemssource = new dataview(dttest1, "typeid <> 25", "", dataviewrowstate.currentrows); ^^
in second 1 need use
dgtest2.itemssource = new dataview(dttest1, "typeid = 25", "", dataviewrowstate.currentrows);
the syntax used rowfilter parameter in dataview constructor same used property expression of datacolumn , not equality operator of c#
edit following comment below. if typeid database field of text datatype need enclose value used in rowfilter between single quotes
dgtest1.itemssource = new dataview(dttest1, "typeid <> '25'", "", dataviewrowstate.currentrows); dgtest2.itemssource = new dataview(dttest1, "typeid = '25'", "", dataviewrowstate.currentrows);
however seems little strange. if typeid field contains numbers should defined numeric datatype.
Comments
Post a Comment