简体   繁体   中英

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. CardId and AttenDate are variables. 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.

I have tried converting the variable value to string and also to datetime format. And even tried by changing datatype in database to date , datetime and also string but unable to match the date value. 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. Do help me.

使用command.Parameters.AddWithValue方法并重写您的SQL:

lCommon.SetCommandObject("select Card_Id,Date from Student_Attendance where Card_Id=@Card_Id AND Date=@AttenDate");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM