Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a classed name dbcon in which i have a function.. i am getting the this error

C#
Error	26	'dbcon.ohh(string)': not all code paths return a value	


C#
public int ohh(String query)
        {
            int c; 
            try
            {
                MAconn = new SqlConnection();
                MAconn.ConnectionString = connectionString;
                MAconn.Open();

                MAcmd = MAconn.CreateCommand();
                MAcmd.CommandText = query;
                c =(int)MAcmd.ExecuteScalar();
                MAconn.Close();
                return c;


            }


and i am using it for count query in that code

C#
<pre>string query= "Select Count(*) FROM roles inner join users on roles.UserID=users.UserID inner join groups on roles.GroupID =groups.GroupID where username ='" + txtusername.Text + "' AND RoleName = '" + DropDownList1.Text + "'";
        int count = obj.ohh(query);
        if (count > 0)
        {
            Label1.Text = "record exits";
        }
        else
        {
            string query = "INSERT INTO ROLES (UserId,GroupId) SELECT UserId,GroupId FROM Users, Groups WHERE username= '" + txtusername.Text + "' AND RoleName='" + DropDownList1.Text + "'";
            bool b=obj.UDI(query);
            
            if (b)
            {
                lblresult.Text = "Inserted";
                //Response.Redirect("Products.aspx");
            }
            else
            {

                lblresult.Text = "Not Inserted";
            }
Posted
Comments
Simon Bang Terkildsen 10-Sep-11 17:21pm    
You have alot of open questions, you should accept the answer which has satisfied your questions. That is not required ofcourse but those people who have freely helped you has done so because they like helping, showing them that you appriciate their help is common courtesy.

1 solution

Like the exception message says not all paths through your method will return a value.
Now you haven't posted your entire ohh method so it's impossible to say where exactly your problem is.
But I guess that you have a catch after your try which does not rethrow the exception and therefore you'll need to have a return statement after your try-catch(-finally) block or in the catch block (though that is considered bad practice)
 
Share this answer
 

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