View Single Post
  #4 (permalink)  
Old September 16th, 2006, 09:40 AM
adyrotaru adyrotaru is offline
Authorized User
Join Date: Jan 2004
Location: Cluj-Napoca, Cluj, Romania.
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to adyrotaru

Hi ratish,
The following piece of code will always yield an "unreachable code detected" warning or even an error compiler message (depend on your compiler's warning level settings).

return sqlDataReader;
// cn.Close();

The reason is because you have an unconditional return statement before the tho so-called "buggy" lines:

// cn.Close();

The code execution will ALWAYS return before reaching those lines (when uncommented).

I recommend that you ALWAYS set your project's settings to "Treat warnings as errors". Alternatively, NEVER let unsolved warnings in your code as more subtile error may be produced later.

Go to: Project/Properties/Configuration Properties/Buil/Treat Warnings as Errors and set this param to "True".
You also may want to change the Warning level, but I also recommend to leave it to level 4 - the most restrictive. I use this level in conjuction with "Treat Warnings as Errors" = True.

Reply With Quote