C# 检查同一记录中的 2 个字段是否与用户输入的内容匹配,例如用户名和密码密码
我想做一个登录类型表单,让员工输入他们的 EmployeeID 和 DOB。到目前为止,我的代码是检查两个文本框是否不为空,确保 EmployeeID 存在,但我不确定如何检查员工的 DOB 是否与他们输入的相同。一些代码如下。
if ((txtEmployeeID.TextLength != 0) && (txtDOB.TextLength != 0))
{
employeesBindingSource.Filter = "EmployeeID ='" + txtEmployeeID.Text + "'";
if (employeesBindingSource.Count > 0)
{
// DOES DOB FOR EMPLOYEE MATCH - NOT SURE WHAT TO PUT HERE
}
}
I want to do a login type form where the Employee enters their EmployeeID and DOB. The code I have so far is to check that both text boxes aren't blank, make sure the EmployeeID exists, but i'm not sure how to check that the DOB for the Employee is the same as what has been entered by them. Some code is below.
if ((txtEmployeeID.TextLength != 0) && (txtDOB.TextLength != 0))
{
employeesBindingSource.Filter = "EmployeeID ='" + txtEmployeeID.Text + "'";
if (employeesBindingSource.Count > 0)
{
// DOES DOB FOR EMPLOYEE MATCH - NOT SURE WHAT TO PUT HERE
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,我们需要 Employee DOB 变量 - 将 DataOfBirthVariable 替换为该变量。
另外,最佳实践是使用 !String.IsNullOrEmpty(txtEmployeeID) 而不是 .TextLength - 只是一个提示。
For this we're going to need the Employee DOB variable - replace DataOfBirthVariable with this.
Also, it's best practice to use !String.IsNullOrEmpty(txtEmployeeID) instead of .TextLength - just a tip.
假设您尝试匹配的 DoB 是 DateTime
请参阅 DateTime.TryParse
Assuming the DoB you trying to match with is a DateTime
See DateTime.TryParse
日期的问题是让您的员工以正确的格式输入数据。
同一事物的所有变体。
您将不得不强制您的员工以您需要的格式输入日期字段。
这与我在代码中使用的一个小路由非常相似。
The problem with a date is getting your employees to input the data in the correct format.
All variations of the same thing.
You are going to have to force your employees to input the date field in a format you require.
That's very similar to a little routing I use in my code.