Swaroop Swaroop - 5 months ago 9
SQL Question

Getting Error: Not all code paths a value

public bool loginpro(string loginas, string dept, string usnm, string pass)
{
try
{
string qrstr;
qrstr = "select * from login where loginas=='" + loginas + "',dept=='" + dept + "',usnm=='" + usnm + "',pass=='" + pass + "'";
Gencon.Open();
SqlCommand cmd = new SqlCommand(qrstr, Gencon);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Gencon.Close();
if (dt.Rows.Count > 0)
{
return true;
}


}
catch (Exception e)
{
return false;
}
}

Answer
public bool loginpro(string loginas, string dept, string usnm, string pass)
{     
 try
    {
        string qrstr;
        qrstr = "select * from login where loginas=='" + loginas + "',dept=='" + dept + "',usnm=='" + usnm + "',pass=='" + pass + "'";
        Gencon.Open();
        SqlCommand cmd = new SqlCommand(qrstr, Gencon);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        Gencon.Close();
        if (dt.Rows.Count > 0)
        {
            return true;
        }
        return false;

}
catch (Exception e)
{
    return false;
}
}

You need a return value after the if... All you will need is a return false and this should work perfectly... sorry for the bad tabbing, if anyone could fix it for me that would be great!

Comments