[英]How to compare date(only) from SQL Server 2008 database to the system date(only) in console application in C#
lCommon.SetCommandObject("select Card_Id,Date from Student_Attendance where Card_Id='" + CardId + "'AND Date='"+AttenDate+"'");
lReader = lCommon.objCommand.ExecuteReader();
bool flag = lReader.Read();
if (flag != true)
{
checkAtenDate = lReader["Date"].ToString();
AttenCardId = lReader["Card_Id"].ToString();
}
I have this code where lcommon
and lreader
are from my classes. 我有这段代码,其中lcommon
和lreader
来自我的课程。 CardId
and AttenDate
are variables. CardId
和AttenDate
是变量。 Now my requirement is to match Card_Id
and Date
from the SQL Server 2008 database, and then on its basis perform a task for that particular value. 现在,我的要求是匹配SQL Server 2008数据库中的Card_Id
和Date
,然后在该基础上为该特定值执行任务。
I have tried converting the variable value to string and also to datetime
format. 我试过将变量值转换为字符串以及datetime
格式。 And even tried by changing datatype in database to date
, datetime
and also string but unable to match the date value. 甚至尝试通过将数据库中的数据类型更改为date
, datetime
以及字符串来尝试,但无法匹配日期值。 Kindly help me in doing it. 请帮助我。 Actually I am trying to match today's date (getting from system) and match it from the database value for per day and perform my task accordingly. 实际上,我正在尝试匹配今天的日期(从系统获取),并从每天的数据库值中匹配它,并相应地执行我的任务。
The present problem is the bool value comes true for flag!= true ie flag's value is false and the values are not stored in the variables. 当前的问题是flag!= true的布尔值变为true,即flag的值为false,并且这些值未存储在变量中。 Do help me. 帮帮我
使用command.Parameters.AddWithValue方法并重写您的SQL:
lCommon.SetCommandObject("select Card_Id,Date from Student_Attendance where Card_Id=@Card_Id AND Date=@AttenDate");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.