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. c# and query result

c# and query result

Scheduled Pinned Locked Moved C#
questioncsharpdatabasetutorial
2 Posts 2 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.
  • U Offline
    U Offline
    User3490
    wrote on last edited by
    #1

    What is the result of a query in c# when is false or is true for example i have the following query and i want to do something when is false. How i manage this? string rfyear = ((string)cmd_year.ExecuteScalar()); i want to manage with "if" if i can to do something like this... if (rfyear.Length == 0) { MessageBox.Show("the query is false "); } else{ MessageBox.Show("OK"); textBox1.Text = rfyear;

    OriginalGriffO 1 Reply Last reply
    0
    • U User3490

      What is the result of a query in c# when is false or is true for example i have the following query and i want to do something when is false. How i manage this? string rfyear = ((string)cmd_year.ExecuteScalar()); i want to manage with "if" if i can to do something like this... if (rfyear.Length == 0) { MessageBox.Show("the query is false "); } else{ MessageBox.Show("OK"); textBox1.Text = rfyear;

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

      It all depends on what your query is actually returning: it is very possible that your line:

      string rfyear = ((string)cmd_year.ExecuteScalar());

      Will not work, but throw an InvalidCastException because the data coming back can't be cast to a string - it may work if you change it to:

      string rfyear = cmd_year.ExecuteScalar().ToString();

      But...I wouldn't recommend it as there is a very good chance that you will get a string containing the name of the type of the value returned. What does your query return when it works and when it fails?

      The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

      "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
      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