Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Dataset Filter Interger

Dataset Filter Interger

Scheduled Pinned Locked Moved C#
question
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Antonius_r3
    wrote on last edited by
    #1

    I have a dataset filled from SqlDataAdapter, and I would like to filter the dataset. The column I would like to filter is customerID, which have int data type. I thought I can use : int cust_search = Int32.Parse(txt_custsearch.Text.ToString()); ds_customer.Tables["Customer_table"].DefaultView.RowFilter = "CustomerID = 'cust_search'"; I know here cust_search have to be in string to have the code to work properly. What should I use to filter interger value in my dataset? Thank you so much in advance.

    D 1 Reply Last reply
    0
    • A Antonius_r3

      I have a dataset filled from SqlDataAdapter, and I would like to filter the dataset. The column I would like to filter is customerID, which have int data type. I thought I can use : int cust_search = Int32.Parse(txt_custsearch.Text.ToString()); ds_customer.Tables["Customer_table"].DefaultView.RowFilter = "CustomerID = 'cust_search'"; I know here cust_search have to be in string to have the code to work properly. What should I use to filter interger value in my dataset? Thank you so much in advance.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Well, for one, don't use .ToString() on a Text property. It's already a String!

      int cust_search = Int32.Parse(txt_custsearch.Text);
      ds_customer.Tables["Customer_table"].DefaultView.RowFilter = "CustomerID = " + cust_search.ToString();

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      A 2 Replies Last reply
      0
      • D Dave Kreskowiak

        Well, for one, don't use .ToString() on a Text property. It's already a String!

        int cust_search = Int32.Parse(txt_custsearch.Text);
        ds_customer.Tables["Customer_table"].DefaultView.RowFilter = "CustomerID = " + cust_search.ToString();

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        A Offline
        A Offline
        Antonius_r3
        wrote on last edited by
        #3

        It worked. Thanks a lot :)

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          Well, for one, don't use .ToString() on a Text property. It's already a String!

          int cust_search = Int32.Parse(txt_custsearch.Text);
          ds_customer.Tables["Customer_table"].DefaultView.RowFilter = "CustomerID = " + cust_search.ToString();

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          A Offline
          A Offline
          Antonius_r3
          wrote on last edited by
          #4

          Is it possible to filter with wildcard? I tried: cust_name_search = txt_custname_search.Text + "%"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; It comes with error saying that "Missing Operand after Mod operation". I know that '%' is the wildcard for Sql Command, but what wildcard do I use for dataview rowfilter, and how do I do it? Thank you very much in advance.

          O 1 Reply Last reply
          0
          • A Antonius_r3

            Is it possible to filter with wildcard? I tried: cust_name_search = txt_custname_search.Text + "%"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; It comes with error saying that "Missing Operand after Mod operation". I know that '%' is the wildcard for Sql Command, but what wildcard do I use for dataview rowfilter, and how do I do it? Thank you very much in advance.

            O Offline
            O Offline
            Orina DCosta
            wrote on last edited by
            #5

            Strings in SQL must be enclosed in single quotes. cust_name_search = "'" + txt_custname_search.Text + "%'"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; Also, Wildcard characters, * and %, are supported and are used with the LIKE operator. Wildcards are allowed only at the beginning and/or end of a filter string. Regards, Orina http://orina.org

            A M 3 Replies Last reply
            0
            • O Orina DCosta

              Strings in SQL must be enclosed in single quotes. cust_name_search = "'" + txt_custname_search.Text + "%'"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; Also, Wildcard characters, * and %, are supported and are used with the LIKE operator. Wildcards are allowed only at the beginning and/or end of a filter string. Regards, Orina http://orina.org

              A Offline
              A Offline
              Antonius_r3
              wrote on last edited by
              #6

              Thank you so much, it works perfectly :)

              1 Reply Last reply
              0
              • O Orina DCosta

                Strings in SQL must be enclosed in single quotes. cust_name_search = "'" + txt_custname_search.Text + "%'"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; Also, Wildcard characters, * and %, are supported and are used with the LIKE operator. Wildcards are allowed only at the beginning and/or end of a filter string. Regards, Orina http://orina.org

                A Offline
                A Offline
                Antonius_r3
                wrote on last edited by
                #7

                Can I actually use LIKE in row filter for interger? For example I have these following record I want to filter: 1100 1101 1200 1201 1202 1203 1300 1301 When I typed '12' in the textbox, only record with 12 as the beginning appear (1200, 1201, 1202, 1203). I tried: string CustomerID = "'" + txt_customerid.Text + "%'"; dataview_cust_search.RowFilter = "CustomerID LIKE " + CustomerID; But error showed up saying that I cannot use LIKE on string with integer. Is there anyway I can do this? Also, is it possible to filter date? Please help. Thank you very much in advance.

                1 Reply Last reply
                0
                • O Orina DCosta

                  Strings in SQL must be enclosed in single quotes. cust_name_search = "'" + txt_custname_search.Text + "%'"; dataview_cust_search.RowFilter = "cust_name LIKE " + cust_name_search; Also, Wildcard characters, * and %, are supported and are used with the LIKE operator. Wildcards are allowed only at the beginning and/or end of a filter string. Regards, Orina http://orina.org

                  M Offline
                  M Offline
                  mikasa
                  wrote on last edited by
                  #8

                  Does anyone know how to Filter a PKey that is a GUID? For some reason, the standard way of treating GUIDs like Strings (which works great in SQL Server) does not work on DataViews! Anyone have a Clue? :wtf:

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups