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. Problem whit loops :x

Problem whit loops :x

Scheduled Pinned Locked Moved C#
databasehelp
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.
  • H Offline
    H Offline
    heelios
    wrote on last edited by
    #1

    Hi, Im having issues whit a loop. When i try to return the function in the loop, it tells me the function has no return value. [WebMethod] public string GetBiosInfo(string Username, string Password) { ConnectionOptions co = new ConnectionOptions(); co.Username = Username; co.Password = Password; ManagementScope ms = new System.Management.ManagementScope("\\\\127.0.0.1\\root\\cimv2", co); ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_BIOS WHERE PrimaryBIOS = TRUE"); ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq); ManagementObjectCollection queryCollection = query.Get(); foreach(ManagementObject mo in queryCollection) { return mo["Name"].ToString(); } }

    N 1 Reply Last reply
    0
    • H heelios

      Hi, Im having issues whit a loop. When i try to return the function in the loop, it tells me the function has no return value. [WebMethod] public string GetBiosInfo(string Username, string Password) { ConnectionOptions co = new ConnectionOptions(); co.Username = Username; co.Password = Password; ManagementScope ms = new System.Management.ManagementScope("\\\\127.0.0.1\\root\\cimv2", co); ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_BIOS WHERE PrimaryBIOS = TRUE"); ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq); ManagementObjectCollection queryCollection = query.Get(); foreach(ManagementObject mo in queryCollection) { return mo["Name"].ToString(); } }

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      What the compiler is saying, is that "not all code paths return a value". This is because you don't return anything outside the foreach loop. The problem lies in the fact that it is theoritically possible that the queryCollection is empty. If it is empty you bypass the loop and go directly to the end of the method. Return something after the loop and the problem will go away. Also, are you sure you only want to execute the loop once? I mean right when you enter the foreach for the first time you will be exiting the method also. -Nathan --------------------------- Hmmm... what's a signature?

      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