protected string getEmailAddr()
        {
            SqlConnection conGet = new SqlConnection(ConfigurationManager.ConnectionStrings["connMSJ"].ConnectionString);
            SqlCommand cmdGet = new SqlCommand("SELECT Email FROM Member WHERE Username=@username", conGet);
            cmdGet.Parameters.AddWithValue("@username", strUsername);
            conGet.Open();
            SqlDataReader dtrGet = cmdGet.ExecuteReader();
            if (dtrGet.Read())
                return dtrGet[0].ToString();
            else
                return null;
            dtrGet.Close();
            conGet.Close();
        }

dtrGet.Close(); Occured the Unreachable Code Detected with Green Colour Underline.
How can i avoid this happen even though there is no problem for me to continue execute my webpage,
But it just seem not nice in the code behind. :P

Unreachable because it's after return. So capture the result/null in a variable and return it at the end of the function, or use a try/finally.

i did tried used the try and finally method enclosed the entire code,
but the error said that the dtrGet.Close cannot be found?
I though is should be okay if i enclose the entire close in Try then finally with Close.?

dtrGet should then be initialized before the try.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.