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. how to recognize null values or not required fileds

how to recognize null values or not required fileds

Scheduled Pinned Locked Moved C#
csharptutorial
7 Posts 6 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.
  • S Offline
    S Offline
    Saeed 394
    wrote on last edited by
    #1

    I have a Winform with some textboxes and comboboxes to search values from sqlserver, i need to recognize when my fields are empty and users dont input anything and by mean they dont need fields,and i have to know they dont want a field or this field is a null i am looking for the best way to handle null values in textboxes and comboboxes in c# thanks

    L A D 3 Replies Last reply
    0
    • S Saeed 394

      I have a Winform with some textboxes and comboboxes to search values from sqlserver, i need to recognize when my fields are empty and users dont input anything and by mean they dont need fields,and i have to know they dont want a field or this field is a null i am looking for the best way to handle null values in textboxes and comboboxes in c# thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I think, there are no null in textbox/combobox. I check it using :

      if(textBox.Text.Trim().Length == 0)
      {
      MessageBox.Show("TextBox is empty");
      }

      if(comboBox.Text.Trim().Length == 0)
      {
      MessageBox.Show("ComboBox is empty");
      }

      S H 2 Replies Last reply
      0
      • L Lost User

        I think, there are no null in textbox/combobox. I check it using :

        if(textBox.Text.Trim().Length == 0)
        {
        MessageBox.Show("TextBox is empty");
        }

        if(comboBox.Text.Trim().Length == 0)
        {
        MessageBox.Show("ComboBox is empty");
        }

        S Offline
        S Offline
        Saeed 394
        wrote on last edited by
        #3

        i want to know how to recognize null values or not required fileds when fileds are empty for example: u have 2 textboxes name and id ,one time u want to select DB all of members that they have no id (it means in search fields id is null field----select name, id from t1 where id = null) another time u need to select members that their id is blank----(select name from t1 where id = '';) thanks again

        OriginalGriffO 1 Reply Last reply
        0
        • S Saeed 394

          i want to know how to recognize null values or not required fileds when fileds are empty for example: u have 2 textboxes name and id ,one time u want to select DB all of members that they have no id (it means in search fields id is null field----select name, id from t1 where id = null) another time u need to select members that their id is blank----(select name from t1 where id = '';) thanks again

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Yes, and stancrm gave you the answer. Just replace the MessageBox with your own logic.

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • S Saeed 394

            I have a Winform with some textboxes and comboboxes to search values from sqlserver, i need to recognize when my fields are empty and users dont input anything and by mean they dont need fields,and i have to know they dont want a field or this field is a null i am looking for the best way to handle null values in textboxes and comboboxes in c# thanks

            A Offline
            A Offline
            Arindam Sinha
            wrote on last edited by
            #5

            Saeed.394 wrote:

            the best way to handle null values in textboxes and comboboxes in c#

            It's a trivial but very important question. I can give you some references which might help you decide upon the 'best'(as I donot even know the best way:)) way. 1. First take a look how you are going to handle null values in ADO.NET[^] 2. Noe it's time to create some controls which can handle null values[^] 3. One more vey important control which you may need is Nullable Datetime picker[^]. I even used in many places.You might need to tweak the code per your requirement. Let me know if this helps you.

            Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this message using rating.

            1 Reply Last reply
            0
            • L Lost User

              I think, there are no null in textbox/combobox. I check it using :

              if(textBox.Text.Trim().Length == 0)
              {
              MessageBox.Show("TextBox is empty");
              }

              if(comboBox.Text.Trim().Length == 0)
              {
              MessageBox.Show("ComboBox is empty");
              }

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              What about:

              if (String.IsNullOrEmpty(textBox.Text))
              {
                  MessageBox.Show("TextBox is empty");
              }
              

              etc.

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              1 Reply Last reply
              0
              • S Saeed 394

                I have a Winform with some textboxes and comboboxes to search values from sqlserver, i need to recognize when my fields are empty and users dont input anything and by mean they dont need fields,and i have to know they dont want a field or this field is a null i am looking for the best way to handle null values in textboxes and comboboxes in c# thanks

                D Offline
                D Offline
                darkelv
                wrote on last edited by
                #7

                You will probably need another control for user to signify they want a null value, ie ID |Text Box| X Search for Null ID if user enter into text box, ignore checkbox and search for ID = 'whatevertheuserenter'. If user checked the checkbox, search for ID Is Null.

                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