none
How to have a DataView Row Filter by <> Operator RRS feed

  • Question

  • Hi,

    I have head hunting problem with the below codes...Really it tooks my holeday, but still not clear...

    Any superiors can help me to clear?

    Thanks

    My Codes

    MyDtb1 = MyOriginalDtb;
    DataView MyDtbView = MyDtb1.DefaultView;
    MyDtbView.Sort = "prn_no,sheet_no,prn_date,pty_name";
    MyDtbView.RowFilter = nullptr;
    //MyDtbView.RowFilter = "prn_status<>'CLOSED'";  ?????????????????

    From the above code DataView RowFilter is not showing all rows, means it omits the last rows.. And hence I achieved by the following code has working good....

    for (int T2 = 0; T2 <= MyDtbView.Count-1; T2++) {
      if (Convert.ToString(MyDtbView[T2]["prn_status"].ToString()) != "CLOSED") {
    // Good and not skipped any rows
      }
    }

    Thanks for the helps


    U.PARANTHAMAN

    Wednesday, January 8, 2020 5:34 AM

All replies

  • Hi U.PARANTHAMAN,
    I made a code demo to test and it can filter data by using the <> operator. It also shows all rows.
    In order to reproduce the situation what you described,could you provide the related datatable?
    Here is my code example.
    DataTable MyDtb1 = new DataTable();
    private void Form1_Load(object sender, EventArgs e)
    {
        MyDtb1.Columns.Add("State");
        MyDtb1.Columns.Add("ZipCode");
        MyDtb1.Rows.Add("Washington", "98052");
        MyDtb1.Rows.Add("California", "90001");
        MyDtb1.Rows.Add("Hawaii", "96807");
        MyDtb1.Rows.Add("Hawaii", "96801");    
    }
    private void button1_Click(object sender, EventArgs e)
    {
        DataView MyDtbView = new DataView(MyDtb1);
        MyDtbView.Sort = "State ASC, ZipCode ASC";
        MyDtbView.RowFilter = "State <>'Washington'";
    //   MyDtbView.RowFilter = null;
        foreach (DataRowView row in MyDtbView)
        {
            Console.WriteLine(" {0} \t {1}", row["State"], row["ZipCode"]);
        }
    }
    Best Regards,
    Daniel Zhang

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 8, 2020 7:45 AM
  • What you're saying doesn't make sense.  I'd be more likely to suspect the code you're using to display the data.  What's special about the rows that were omitted?  Is it possible prn_status is NULL?

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Wednesday, January 8, 2020 10:16 PM