简体   繁体   English

如何在C#中的控制台应用程序中将SQL Server 2008数据库中的日期(仅)与系统日期(仅)进行比较

[英]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. 我有这段代码,其中lcommonlreader来自我的课程。 CardId and AttenDate are variables. CardIdAttenDate是变量。 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_IdDate ,然后在该基础上为该特定值执行任务。

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. 甚至尝试通过将数据库中的数据类型更改为datedatetime以及字符串来尝试,但无法匹配日期值。 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.

相关问题 在窗体C#Visual Studio中比较两个日期起始日期和数据库SQL Server中的日期 - Compare Two Date From Date at Form C# Visual Studio and Date From Database SQL Server 如何授予SQL Server 2008数据库从C#Windows应用程序中的客户端系统插入数据的权限? - How to give the permissions to sql server 2008 database to insert the data from client system in c# windows application? 从C#Winforms在SQL数据库中仅保存日期,而不保存时间 - Only Date is saved and not time in sql Database from C# winforms 如何从SQL Server 2008中的SQL Job运行C#控制台应用程序? - How to run C# Console application from SQL Job in SQL Server 2008? 如何比较sql数据库中的日期与当前日期以允许访问C#mvc5中的页面 - How to compare a date from sql database with current date to allow access page in C# mvc5 将C#日期传递给SQL Server 2008 - Passing C# Date to SQL Server 2008 如何仅比较sql server 2008中的datetime字段的年份? - How to compare only year from a datetime field in sql server 2008? SQL Server和C#:筛选System.Date-仅在00:00:00生成结果条目 - SQL Server & C# : filter for System.Date - results only entries at 00:00:00 SQL Server / C#:筛选System.Date-仅在00:00:00生成结果条目 - SQL Server / C# : Filter for System.Date - results only entries at 00:00:00 C#Linq只比较datetime属性中的日期 - C# Linq compare only date from a datetime property
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM