Click here to Skip to main content
15,881,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have added existing file into my project.file is .cs format when i add this file the error comes where i have written: return false.error -unreachable code detected.help me?

C#
public bool check_bids_auction(int mid)
    {
        string sqlstr = "select bid from bid_details where mediaid=" + mid + " ";
        SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        if (ds.Tables[0].Rows.Count <= 0)
        {
            return true;
        }
        else
        {
            return false;
        }
        return false;//error on this line

    }
Posted
Updated 14-Jun-12 18:37pm
v3
Comments
Sergey Alexandrovich Kryukov 15-Jun-12 0:36am    
Code sample, please.
--SA

1 solution

It would be a matter of seconds to point out your bug if we has a code sample from you. This is a very simple thing: the compiler detected that there is some code which never can be executed. For example, if you write some lines of code right after after return, it's apparent that none of those lines can be executed.

Look properly at your code and you will see it. If you still cannot see it (I cannot imagine why would you fail to see it), them create a code sample (very short) and post it (use "Improve question").

—SA
 
Share this answer
 
Comments
Sandeep Mewara 15-Jun-12 1:36am    
As SA already pointed out details of it,
if (ds.Tables[0].Rows.Count <= 0)
{
return true;
}
else
{
return false;
}
return false;//error on this line

in above code, you have put a return after an if-else, where based on whatever condition, one return of if or else would get executed. Thus, the last return is redundant and of no use - unreachable!
SoMad 15-Jun-12 2:14am    
Yes, but how can I upvote your solution when you put it here? :)

Soren Madsen
Sandeep Mewara 15-Jun-12 2:50am    
Upvote SA's answer. He already replied correctly based on whatever was shared, I just added code reference once it was shared by OP.

:)
SoMad 15-Jun-12 3:27am    
I already did. I figured that was your reason for posting your comment under his solution.

Soren Madsen
Sandeep Mewara 15-Jun-12 4:51am    
:) :thumbsup:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900