Dataview RowFilter

G

Guest

I am using a dataview to filter rows that have an 'access level' (this is a
column) less than the users 'access level'. The dataview is created with:

ContactDataView = New DataView(Me._stuadrk, _
"CONTACT_TYPE_PL <= '" +
Me._synonyms.UserPriv + "'", _
"SEQUENCE_NO", _
DataViewRowState.CurrentRows)
CONTACT_TYPE_PL is a column derived from an expression, it's type is string.
The type of Me._synonyms.UserPriv is also string. The underlying dataset is
set to be case sensitive.
My problem is that this filter fails when it should succeed. If the value
of CONTACT_TYPE_PL in a particular row is R and the value of Userpriv is ~
then the row is not included, it should be.
CONTACT_TYPE_PL UserPriv Rowindataview
R w Yes
R ~ No

However the relationship should succeed! Here is console output and how it
is generated:

Console.WriteLine("CONTACTS(LOAD): UA: " + Me._synonyms.UserPriv + _
" DataviewRowCount: " + ContactDataView.Count.ToString)

Console.WriteLine(Chr(9) + ContactDataView.RowFilter)

For Each DR As DataRow In Me._stuadrk.Rows

Console.WriteLine(Chr(9) + DR.Item("CONTACT_TYPE_PL") + Chr(9) + _
(CType(DR.Item("CONTACT_TYPE_PL"), String) <= _
Me._synonyms.UserPriv).ToString + Chr(9) + _
CType(DR.Item("SEQUENCE_NO"), Integer).ToString)

Next

CONTACTS(LOAD): UA: ~ DataviewRowCount: 2
CONTACT_TYPE_PL <= '~'
R True 1
True 2
True 3

Any help?
 
W

W.G. Ryan eMVP

Robert:

I'm not sure how the Column is computer but is there a particular reason
you're use <= vs. <>? The only filter in the expression is on
CONTACT_TYPE_PL not both fields. What I think might be happening is that
you're comparing CONTACT_TYPE_PL <= "~" and I belive R is less than "~"

DataTable dt = new DataTable();

DataColumn dc = new DataColumn("ValueName", Type.GetType("System.String"));

dt.Columns.Add(dc);

DataRow dro = dt.NewRow();

dt.Rows.Add(dro);

dt.Rows[0][0] = "R";

DataRow dro2 = dt.NewRow();

dt.Rows.Add(dro2);

dt.Rows[1][0] = "R";

DataView dv = dt.DefaultView;

dv.RowFilter = "ValueName <= '~'";

//dv.Count = 0 here but if I change the values of R to ~ then I get 2
 
G

Guest

Hi, W.G. Ryan,

Thanks for responding. The behavior you got in your test routine is the
problem. When the rowfilter is "Valuename <= '~'" and the value of the
Valuename column is R then you should get 2 rows not zero. ~ is greater than
all letters, numbers special characters.

Thanks,
Robert Pfeffer

W.G. Ryan eMVP said:
Robert:

I'm not sure how the Column is computer but is there a particular reason
you're use <= vs. <>? The only filter in the expression is on
CONTACT_TYPE_PL not both fields. What I think might be happening is that
you're comparing CONTACT_TYPE_PL <= "~" and I belive R is less than "~"

DataTable dt = new DataTable();

DataColumn dc = new DataColumn("ValueName", Type.GetType("System.String"));

dt.Columns.Add(dc);

DataRow dro = dt.NewRow();

dt.Rows.Add(dro);

dt.Rows[0][0] = "R";

DataRow dro2 = dt.NewRow();

dt.Rows.Add(dro2);

dt.Rows[1][0] = "R";

DataView dv = dt.DefaultView;

dv.RowFilter = "ValueName <= '~'";

//dv.Count = 0 here but if I change the values of R to ~ then I get 2
 
K

Kevin Yu [MSFT]

Hi Robert,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when you're trying to filter rows by
comparing strings, R seems to be larger than ~. If there is any
misunderstanding, please feel free to let me know.

In this case, I think string comparison is not just how we compare
characters. So we cannot filter string values like that. In my opinion, we
can try to chagne the column type from string to char. put a single char in
the field will make the filter work as expected.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Hi Kevin,
I assumed that strings would compare as a 'string' of ascii characters.
In the console output, the comparison of R is less than ~ ( ~ is the highest
displayable character in ascii). It seems that string comparisons should be
based on the ascii characters of the string.

I got around this by converting the columns character to an integer:

Convert(Convert(CONTACT_TYPE_PL,'System.Char'),'System.Int64') <= " +
Asc(Me._synonyms.UserPriv).ToString

I personnally think it should compare as ascii characters (or whatever code
page, code set that is being used).

Looking at my code, I realize I can change to char and compare as
characters. I will change and let you know the outcome.

Thanks for your assistance

Robert pfeffer
 
K

Kevin Yu [MSFT]

Yes, Robert, we can convert it to char. You can see my suggestion on that
in my last post.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top