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 check value in IF statement..

How to check value in IF statement..

Scheduled Pinned Locked Moved C#
questioncsharpdatabasetutorial
9 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.
  • T Offline
    T Offline
    Tash18
    wrote on last edited by
    #1

    Hi guyzz.. i have a doubt may be i have a query in C# coding and the query returns a string... Now i need to perform a check using if statement, my check is that if the query returns any string value then grant permission else access denied... Now my doubt is how do i specify "return any string value" in the if condition... plz advice...

    If(query == ?????)
    {
    permission granted
    }

    C R 2 Replies Last reply
    0
    • T Tash18

      Hi guyzz.. i have a doubt may be i have a query in C# coding and the query returns a string... Now i need to perform a check using if statement, my check is that if the query returns any string value then grant permission else access denied... Now my doubt is how do i specify "return any string value" in the if condition... plz advice...

      If(query == ?????)
      {
      permission granted
      }

      C Offline
      C Offline
      Calla
      wrote on last edited by
      #2

      Either check if (query.Length > 0) or if (query != string.Empty). If your query variable can be null then you can check if(query != null). Good luck! :) so your statement should read:

      if (query != null)
      {
      if (query.Length > 0)
      //permission granted
      }

      T 1 Reply Last reply
      0
      • C Calla

        Either check if (query.Length > 0) or if (query != string.Empty). If your query variable can be null then you can check if(query != null). Good luck! :) so your statement should read:

        if (query != null)
        {
        if (query.Length > 0)
        //permission granted
        }

        T Offline
        T Offline
        Tash18
        wrote on last edited by
        #3

        Thanx.. its actually very silly doubt... the logic dint strike me as im a new comer in programming... Thanx alot.. regards, tash

        S 1 Reply Last reply
        0
        • T Tash18

          Thanx.. its actually very silly doubt... the logic dint strike me as im a new comer in programming... Thanx alot.. regards, tash

          S Offline
          S Offline
          Som Shekhar
          wrote on last edited by
          #4

          to check if a string is null or empty, usually if(!String.IsNullOrEmpty(value)) should be used. This checks for both empty and null strings.

          T C 2 Replies Last reply
          0
          • S Som Shekhar

            to check if a string is null or empty, usually if(!String.IsNullOrEmpty(value)) should be used. This checks for both empty and null strings.

            T Offline
            T Offline
            Tash18
            wrote on last edited by
            #5

            Thanx buddy... Regards, Tash

            S 1 Reply Last reply
            0
            • T Tash18

              Thanx buddy... Regards, Tash

              S Offline
              S Offline
              Som Shekhar
              wrote on last edited by
              #6

              welcome!! :)

              1 Reply Last reply
              0
              • S Som Shekhar

                to check if a string is null or empty, usually if(!String.IsNullOrEmpty(value)) should be used. This checks for both empty and null strings.

                C Offline
                C Offline
                Calla
                wrote on last edited by
                #7

                How come is still don't remember this String method..? ;)

                S 1 Reply Last reply
                0
                • C Calla

                  How come is still don't remember this String method..? ;)

                  S Offline
                  S Offline
                  Som Shekhar
                  wrote on last edited by
                  #8

                  Happens buddy!!! All in a day's work.

                  1 Reply Last reply
                  0
                  • T Tash18

                    Hi guyzz.. i have a doubt may be i have a query in C# coding and the query returns a string... Now i need to perform a check using if statement, my check is that if the query returns any string value then grant permission else access denied... Now my doubt is how do i specify "return any string value" in the if condition... plz advice...

                    If(query == ?????)
                    {
                    permission granted
                    }

                    R Offline
                    R Offline
                    realJSOP
                    wrote on last edited by
                    #9

                    if (!string.IsNullOrEmpty(query))
                    {
                    // premission granted
                    }

                    .45 ACP - because shooting twice is just silly
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                    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