从系统日期(仅)比较存储在数据库中的日期 [英] Compare date stored in database from the System date(only)

查看:76
本文介绍了从系统日期(仅)比较存储在数据库中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
                }





我有这个代码,其中lcommon和lreader来自我的课程。 CardId和AttenDate是变量。现在我的要求是从数据库(sql server 2008)匹配Card_Id和Date,然后在其基础上执行该特定值的任务。我已经尝试将变量值转换为字符串,也转换为日期时间格式。甚至尝试通过更改数据库中的数据类型到date,datetime和string但无法匹配日期值。请帮助我这样做。实际上我正在尝试匹配今天的日期(从系统获取)并将其与每天的数据库值相匹配并相应地执行我的任务。



目前的问题是标志的bool值为true!= true,即flag的值为false,值不存储在变量中。请帮帮我。



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 database(sql server 2008) 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 i.e. flag's value is false and the values are not stored in the variables. Do help me.

推荐答案

使用这个

------------------- -





use this
---------------------


--use dd/MM/yyyy '13/01/1995' Format for AttenDate variable
"select Card_Id,Date from Student_Attendance where Card_Id='" + CardId + "'AND CONVERT(Varchar,Date, 100) = CONVERT(Varchar,'"+AttenDate+"', 100)"


这篇关于从系统日期(仅)比较存储在数据库中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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