2 Replies - 555 Views - Last Post: 23 February 2017 - 01:17 AM Rate Topic: -----

#1 ahmedba  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 141
  • Joined: 24-January 14

why else statement for function UserExistsToday not work

Posted 22 February 2017 - 04:51 PM

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

bool c = QRC.UserExists(textBox1.Text);

                    bool b = UserExistsToday();

                    if (c == true)
                    {
                       if (b == true)
                       {

                               label8.Text = "User added today";


                       }

                       else
                       {

                            label8.Text = "User added before";

                        }
                    }
                    }
                    else
                    {

                        label8.Text = "User added first time";

                    }
my functions 
label6 represent datetoday

public bool UserExistsToday()
        {

            OleDbConnection cn = new OleDbConnection(connection);
            string str = $"select * from [Sheet1$] WHERE UserNo='{textBox1.Text}' AND DatePrint = '{label6.Text}'";
            OleDbCommand cmd = new OleDbCommand(str, cn);
            cn.Open();
            var reader = cmd.ExecuteReader();
            return reader.HasRows;


        }

public bool UserExists(string UserNo)
        {

            OleDbConnection cn = new OleDbConnection(connection);
            string str = "SELECT UserNo FROM  [Sheet1$] WHERE UserNo = @UserNo";
            OleDbCommand cmd = new OleDbCommand(str, cn);
            cmd.Parameters.AddWithValue("@UserNo", UserNo);

            cn.Open();
            var reader = cmd.ExecuteReader();
            return reader.HasRows;


        }

This post has been edited by ahmedba: 22 February 2017 - 04:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: why else statement for function UserExistsToday not work

#2 andrewsw  Icon User is offline

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,909
  • Joined: 12-December 12

Re: why else statement for function UserExistsToday not work

Posted 23 February 2017 - 01:10 AM

Question moved out of Discussion Lounge.
Was This Post Helpful? 0
  • +
  • -

#3 JapanDave  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 366
  • Joined: 01-February 16

Re: why else statement for function UserExistsToday not work

Posted 23 February 2017 - 01:17 AM

Why are you not also querying the date if it is linked to a user existing or not? At present , iot seems you are just qurying the DB to see if the user number exists.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1