RowFilter ColumnName <> Value (Does Not Work)

G

Guest

RowFilter ColumnName <> Value Does not return any rows when data exits.

My data has a notes string notes field which contains the values Good, Not Good, and ''. Filtering on Good (DS.DefualtView.RowFilter = "Notes = 'Good'“ returns 4 rows but the inverse (DS.DefualtView.RowFilter = "Notes <> 'Good'" returns no rows?

Help ..
 
W

William Ryan eMVP

Hi Bick:

I don't think that's the problem. How many rows that aren't equal to good
are in the table? YOu can definitely use <>
http://www.knowdotnet.com/articles/advancedrowfilter.html and I do it all of
the time, so my guess is that something is incorrect about the row values or
you have some other property like the RowStateFilter set which is making it
look like this is the probem.

Cna you post the exact code you are using and do a Debug.WriteLine with
those values n questino?

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Bick Lamono said:
RowFilter ColumnName <> Value Does not return any rows when data exits.

My data has a notes string notes field which contains the values Good, Not
Good, and ''. Filtering on Good (DS.DefualtView.RowFilter = "Notes = 'Good'"
 
J

Jon Skeet [C# MVP]

Bick Lamono said:
The DataTable (tblList) has 2914 verified in the immediates window

If you send me an email I will send you the access db. Filtering on
'Good' (RowFilter = "Notes = 'Good'" works fine and returns 4 rows,
so I know the colum is right. I have been trying different
RowStateFilter's. I have tried both current and none with no luck

There's no need for an Access DB here - just create the table in code,
and you can post the whole program here. Here's an example in C#:

using System;
using System.Data;

public class Test
{
static void Main()
{
DataTable table = new DataTable("Test");
table.Columns.Add("ID", typeof(int));
table.Columns.Add("FirstName", typeof(string));
table.Columns.Add("SecondName", typeof(string));

table.Rows.Add(new object[]{0, "Jon", "Skeet"});
table.Rows.Add(new object[]{1, "Jon", "NotSkeet"});
table.Rows.Add(new object[]{2, "Bick", "Lamono"});

DataView view = new DataView();
view.Table = table;

ShowView(view);
view.RowFilter = "FirstName = 'Jon'";
ShowView(view);
view.RowFilter = "FirstName <> 'Jon'";
ShowView(view);
}

static void ShowView(DataView view)
{
Console.WriteLine("Row filter=\"{0}\"", view.RowFilter);
foreach (DataRowView row in view)
{
Console.WriteLine ("{0} {1} {2}", row["ID"],
row["FirstName"], row["SecondName"]);
}
Console.WriteLine();
}
}

It comes up with exactly the result I'd expect:
Row filter=""
0 Jon Skeet
1 Jon NotSkeet
2 Bick Lamono

Row filter="FirstName = 'Jon'"
0 Jon Skeet
1 Jon NotSkeet

Row filter="FirstName <> 'Jon'"
2 Bick Lamono


Now, can you come up with a similar short but complete program which
demonstrates the problem you're having?
 
W

William Ryan eMVP

Hi Bick:

Jon raises a good point here. I got the code but couldn't get the Access db
to open so i went with his approach. The queries you are using are pretty
complex and it'd take me a while to track it down but I set the rowfilter to
<> on the first line you gave me and it worked like I'd expect. With all of
the concatenation that's going on, I'm 99.99999% sure that it's one of those
that's the problem. If I have some time tonight I'll walk through it and
find the problem but i can't promise anything b/c there's a lot of code. In
the interim, I'd just start commenting out lines of code (that's what I did)
and eliminating them. I got <> to work on the first line so it's not the
problem,. I'll try to nail it down for you shortly.

Bill

--
W.G. Ryan MVP Windows - Embedded

www.devbuzz.com
www.knowdotnet.com
http://www.msmvps.com/williamryan/
Bick Lamono said:
The DataTable (tblList) has 2914 verified in the immediates window

If you send me an email I will send you the access db. Filtering on
'Good' (RowFilter = "Notes = 'Good'" works fine and returns 4 rows, so I
know the colum is right. I have been trying different RowStateFilter's. I
have tried both current and none with no luck
Here is the code

Private Sub BindGrid()
Dim oQuestionLiteralRows() As FormDS.tblQuestionLiteralRow
Dim oQuestionLiteralRow As FormDS.tblQuestionLiteralRow
Dim oQuestionRow As FormDS.tblQuestionsRow
Dim QuestionID As Int32
Dim LiteralID As Int32

Try
If CampaignDS1 Is Nothing Then

Else
CampaignDS1.tblList.DefaultView.RowFilter = ""
CampaignDS1.tblList.DefaultView.RowStateFilter = DataViewRowState.CurrentRows
If (Me.ddFilterCol.SelectedValue.ToString <> "No Filter"
And Me.ddFilterCol.SelectedValue.ToString said:
Select Case Me.ddFilterCol.SelectedValue.ToString

Case "Link", "Notes"
If Me.ddFilterModifier.SelectedValue = "Like" Then
CampaignDS1.tblList.DefaultView.RowFilter
= String.Concat(Me.ddFilterCol.SelectedValue.ToString, " Like '",
Me.txtFilterText.Value, "%'")
ElseIf Me.ddFilterModifier.SelectedValue = "Like%" Then
CampaignDS1.tblList.DefaultView.RowFilter
= String.Concat(Me.ddFilterCol.SelectedValue.ToString, " Like '%",
Me.txtFilterText.Value, "%'")
Else
CampaignDS1.tblList.DefaultView.RowFilter
= String.Concat(Me.ddFilterCol.SelectedValue.ToString, " ",
Me.ddFilterModifier.SelectedValue, " '", Me.txtFilterText.Value, "'")
End If
Case "BadEmail", "Registered"
If Me.txtFilterText.Value.ToLower = "yes" Or
Me.txtFilterText.Value.ToLower = "no" Then
CampaignDS1.tblList.DefaultView.RowFilter
= String.Concat(Me.ddFilterCol.SelectedValue.ToString, " = ", " '",
Me.txtFilterText.Value, "'")
Else
Session("Alert") =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " can only be yes or
no.")
End If
Case "EmailsSent", "NoReg", "LoadID", "ID"
If Me.ddFilterModifier.SelectedValue <> "Like"
And Me.ddFilterModifier.SelectedValue said:
If IsNumeric(Me.txtFilterText.Value) Then
CampaignDS1.tblList.DefaultView.RowFilter =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " ",
Me.ddFilterModifier.SelectedValue, " ", Me.txtFilterText.Value)
Else
Session("Alert") =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " can only be filtered
with numeric data!")
End If
Else
Session("Alert") =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " can only be filtered
using a boolean operator ( said:
End If
Case Else
'if this is a question use the literal for filtering
If
IsNumeric(Me.ddFilterCol.SelectedValue.ToString.Substring(1)) AndAlso
CInt(Me.ddFilterCol.SelectedValue.ToString.Substring(1)) > 199 Then
QuestionID = CInt(Me.ddFilterCol.SelectedValue.ToString.Substring(1))
oQuestionRow = FormDS1.tblQuestions.FindByQuestionID(QuestionID)

If oQuestionRow Is Nothing Then
Exit Select
Else
LiteralID = 0
oQuestionLiteralRows = oQuestionRow.GettblQuestionLiteralRows
For Each oQuestionLiteralRow In oQuestionLiteralRows
If
Me.txtFilterText.Value.ToLower.Trim =
oQuestionLiteralRow.AnswerText.ToLower.Trim Then
LiteralID = oQuestionLiteralRow.LiteralID
Exit For
End If
Next
If LiteralID <> 0 Then
CampaignDS1.tblList.DefaultView.RowFilter =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " = ", LiteralID)
End If
End If
Else
If Me.ddFilterModifier.SelectedValue = "Like" Then
CampaignDS1.tblList.DefaultView.RowFilter =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " ",
Me.ddFilterModifier.SelectedValue, " '", Me.txtFilterText.Value, "%'")
ElseIf Me.ddFilterModifier.SelectedValue = "Like%" Then
CampaignDS1.tblList.DefaultView.RowFilter =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " Like '%",
Me.txtFilterText.Value, "%'")
CampaignDS1.tblList.DefaultView.RowFilter =
String.Concat(Me.ddFilterCol.SelectedValue.ToString, " ",
Me.ddFilterModifier.SelectedValue, " '", Me.txtFilterText.Value, "'")
 

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