ahmed salah

ahmed salah

  • NA
  • 530
  • 142k

why else statement for function UserExistsToday not work

Feb 22 2017 6:57 PM

why else statement for function UserExistsToday not work


I work in c# windows form vs 2015 selecting data from excel
problem i face it
supose i have in excel file
user id dateprint
1001 22/02/2017

if try add this user 1001 again with date 23/02/2017
it must give me message this user found before
but this is not happen and this is actually my problem
my code

  1. bool c = QRC.UserExists(textBox1.Text);  
  2.   
  3. bool b = UserExistsToday();  
  4.   
  5. if (c == true)  
  6.   
  7. {  
  8.   
  9. if (b == true)  
  10.   
  11. {  
  12.   
  13.   
  14. label8.Text = "User added today";  
  15.   
  16.   
  17.   
  18. }  
  19.   
  20.   
  21. else  
  22.   
  23. {  
  24.   
  25.   
  26. label8.Text = "User added before";  
  27.   
  28.   
  29. }  
  30. }  
  31.   
  32. }  
  33.   
  34. else  
  35.   
  36. {  
  37.   
  38. label8.Text = "User added first time";  
  39.   
  40.   
  41. }  
  42.   
  43. my functions  
  44.   
  45. label6 represent datetoday  
  46.   
  47.   
  48. public bool UserExistsToday()  
  49. {  
  50. OleDbConnection cn = newOleDbConnection(connection);  
  51.   
  52. string str = $"select * from [Sheet1$] WHERE UserNo='{textBox1.Text}' AND DatePrint = '{label6.Text}'";  
  53.   
  54. OleDbCommand cmd = newOleDbCommand(str, cn);  
  55.   
  56. cn.Open();  
  57.   
  58. var reader = cmd.ExecuteReader();  
  59.   
  60. return reader.HasRows;  
  61.   
  62. }  
  63.   
  64. public bool UserExists(string UserNo)  
  65.   
  66. {  
  67.   
  68. OleDbConnection cn = newOleDbConnection(connection);  
  69.   
  70. string str = "SELECT UserNo FROM [Sheet1$] WHERE UserNo = @UserNo";  
  71.   
  72. OleDbCommand cmd = newOleDbCommand(str, cn);  
  73.   
  74. cmd.Parameters.AddWithValue("@UserNo", UserNo);  
  75.   
  76. cn.Open();  
  77.   
  78. var reader = cmd.ExecuteReader();  
  79.   
  80. return reader.HasRows;  
  81. }  
 


Answers (3)