not all code path return a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parul Vinod
    New Member
    • Aug 2011
    • 36

    not all code path return a value

    My code is showing an error that not all code paths return a value.
    Code:
    public bool ValidSession(string sessionid,string username)
    {
    SqConnection con=new Sqlconnection(str);
    string query,query1,database;
    DateTime date1;
    query="select username from ActiveUsers where sessionId='"+ sessionid +"';
    query1="select datetime from ActiveUsers where sessionid='" + sessionid + "'"
    con.Open();
    SqlCommand cmd= new SqlCommand(query,con);
    SqlDataReader dr;
    dr=cmd.ExecuteReader();
    if(dr.Read())
    {
    database=dr.GetString(0);
    if(database.CompareTo(username)==0)
    {
    dr.close();
    cmd.Dispose();
    SqlCommand cmd1=new SqlCommand(query1,con);
    SqlDataReader dr1;
    dr1=cmd1.ExecuteReader();
    if(dr1.Read())
    {
    date1=dr1.GetDateTime(0);
    TimeSpan difference;
    difference=DateTime.Now-date1;
    if(difference.TotalMinutes> 30)
    {
    dr1.Close();
    cmd1.Dispose();
    con.Close();
    con.Dispose();
    return false;
    }
    else
    {
    dr1.Close();
    cmd1.Dispose();
    con.close();
    con.Dispose();
    return true;
    }
    }
    }
    else
    {
    dr.Close();
    cmd.Dispose();
    con.Close();
    con.Dispose();
    return false;
    }
    }
    else
    {
    dr.Close();
    cmd.Dispose();
    con.Close();
    con.Dispose();
    return false;
    }
    }
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You don't return anything if dr1.Read() is false.

    Comment

    • Parul Vinod
      New Member
      • Aug 2011
      • 36

      #3
      Thanks Rabbit, bug got fixed by writting the else part.

      Comment

      Working...