为什么函数userexiststoday的其他声明不起作用以及如何解决它 [英] Why else statement for function userexiststoday not work and how to solve it

查看:64
本文介绍了为什么函数userexiststoday的其他声明不起作用以及如何解决它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#windows form vs 2015从excel中选择数据

问题我面对它

supose我有excel文件

用户id dateprint

1001 22/02/2017



如果尝试再次添加此用户1001日期23/02/2017

它必须给我这个用​​户之前发现的消息

但这不会发生,这实际上是我的问题

我的代码



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 = newOleDbConnection(connection);  
  
string str = $"select * from [Sheet1$] WHERE UserNo='{textBox1.Text}' AND DatePrint = '{label6.Text}'";  
  
OleDbCommand cmd = newOleDbCommand(str, 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.Parameters.AddWithValue("@UserNo", UserNo);  
  
cn.Open();  
  
var reader = cmd.ExecuteReader();  
  
return reader.HasRows;  
}





我的尝试:





What I have tried:

why else statement for function UserExistsToday not work and how to solve it

推荐答案

< span class =code-string> select * from [Sheet1
"select * from [Sheet1


WHERE UserNo ='{textBox1.Text}' AND DatePrint ='{label6.Text}';

OleDbCommand cmd = newOleDbCommand(str,cn);

cn.Open();

var reader = cmd.ExecuteReader();

return reader.HasRows;

}

public bool UserExists(< span class =code-keyword> string UserNo)

{

OleDbConnection cn = newOleDbConnection(connection);

string str = SELECT UserNo FROM [Sheet1
WHERE UserNo='{textBox1.Text}' AND DatePrint = '{label6.Text}'"; OleDbCommand cmd = newOleDbCommand(str, 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.Parameters.AddWithValue( @ UserNo,UserNo);

cn.Open();

var reader = cmd.ExecuteReader();

return reader.HasRows;
}
WHERE UserNo = @UserNo"; OleDbCommand cmd = newOleDbCommand(str, cn); cmd.Parameters.AddWithValue("@UserNo", UserNo); cn.Open(); var reader = cmd.ExecuteReader(); return reader.HasRows; }





我的尝试:





What I have tried:

why else statement for function UserExistsToday not work and how to solve it


这篇关于为什么函数userexiststoday的其他声明不起作用以及如何解决它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆