---
title: "Why else statement for function userexiststoday not work and how to solve it"  
description: "Why else statement for function userexiststoday not work and how to solve it"  
author: "Abeer Shlby"  
published: 2017-02-22  
updated: 2017-02-22  
canonical: https://www.mindstick.com/forum/34266/why-else-statement-for-function-userexiststoday-not-work-and-how-to-solve-it  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# Why else statement for function userexiststoday not work and how to solve it

I work in c# [windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) vs 2015 selecting [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from [excel](https://www.mindstick.com/articles/12937/how-to-import-excel-data-in-sql-server-2014) \
[problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) i face it\
supose i have in excel file\
[user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) id dateprint\
1001 22/02/2017\
\
if try add this user 1001 again with [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) 23/02/2017\
it [must](https://www.mindstick.com/articles/12978/top-reasons-why-every-magento-ecommerce-store-must-opt-for-mobile-app) give me [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) this user found before\
but this is not happen and this is actually my problem\
my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)

```
bool c = QRC.UserExists(textBox1.Text);
bool b = UserExistsToday();
if (c == true)
{
if (b == true)
{
label8label8.Text = "User added today";
}
else
{
label8
label8.Text = "User added before";
}
}
}
else
{
label8
label8.Text = "User added first time";
}
my functions
label6 represent datetoday
label6 represent datetoday
public bool UserExistsToday()
{
OleDbConnection cn = newOleDbConnection(connection);
string str = $"select * from [Sheet1$] WHERE UserNo='{textBox1.Text}' AND DatePrint = '{label6.Text}'";
OleDbCommand cmd = newOleDbCommand(str, cn);
cn
cn.Open();
var reader = cmd.ExecuteReader();
return reader.HasRows;
}
public bool UserExists(string UserNo)
{ OleDbConnection cn = newOleDbConnection(connection);
string str = "SELECT UserNo FROM [Sheet1$] WHERE UserNo = @UserNo";
OleDbCommand cmd = newOleDbCommand(str, cn);
cmd
cmd.Parameters.AddWithValue("@UserNo", UserNo);
cn
cn.Open();
var reader = cmd.ExecuteReader();
return reader.HasRows;
}
```

> \


---

Original Source: https://www.mindstick.com/forum/34266/why-else-statement-for-function-userexiststoday-not-work-and-how-to-solve-it

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
