469,358 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

not all code path return a value

My code is showing an error that not all code paths return a value.
Expand|Select|Wrap|Line Numbers
  1. public bool ValidSession(string sessionid,string username)
  2. {
  3. SqConnection con=new Sqlconnection(str);
  4. string query,query1,database;
  5. DateTime date1;
  6. query="select username from ActiveUsers where sessionId='"+ sessionid +"';
  7. query1="select datetime from ActiveUsers where sessionid='" + sessionid + "'"
  8. con.Open();
  9. SqlCommand cmd= new SqlCommand(query,con);
  10. SqlDataReader dr;
  11. dr=cmd.ExecuteReader();
  12. if(dr.Read())
  13. {
  14. database=dr.GetString(0);
  15. if(database.CompareTo(username)==0)
  16. {
  17. dr.close();
  18. cmd.Dispose();
  19. SqlCommand cmd1=new SqlCommand(query1,con);
  20. SqlDataReader dr1;
  21. dr1=cmd1.ExecuteReader();
  22. if(dr1.Read())
  23. {
  24. date1=dr1.GetDateTime(0);
  25. TimeSpan difference;
  26. difference=DateTime.Now-date1;
  27. if(difference.TotalMinutes> 30)
  28. {
  29. dr1.Close();
  30. cmd1.Dispose();
  31. con.Close();
  32. con.Dispose();
  33. return false;
  34. }
  35. else
  36. {
  37. dr1.Close();
  38. cmd1.Dispose();
  39. con.close();
  40. con.Dispose();
  41. return true;
  42. }
  43. }
  44. }
  45. else
  46. {
  47. dr.Close();
  48. cmd.Dispose();
  49. con.Close();
  50. con.Dispose();
  51. return false;
  52. }
  53. }
  54. else
  55. {
  56. dr.Close();
  57. cmd.Dispose();
  58. con.Close();
  59. con.Dispose();
  60. return false;
  61. }
  62. }
  63. }
Feb 3 '12 #1

✓ answered by Rabbit

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

2 1728
Rabbit
12,516 Expert Mod 8TB
You don't return anything if dr1.Read() is false.
Feb 3 '12 #2
Thanks Rabbit, bug got fixed by writting the else part.
Feb 4 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Gernold Schneider | last post: by
4 posts views Thread by Chris Bower | last post: by
5 posts views Thread by Dmitriy Lapshin [C# / .NET MVP] | last post: by
1 post views Thread by Savas Ates | last post: by
6 posts views Thread by Tim Roberts | last post: by
4 posts views Thread by Michele Petrazzo | last post: by
7 posts views Thread by Terry Olsen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.