Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 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.
Posted
Comments
kool15th 25-Nov-13 6:11am    
By Assigning AttenDate="25-11-2013" it matches successfully but changing it to ToShortDateString or ToString("dd/MM/yyyy") it doesn't match. currently I am trying by date value as varchar in database and also the AttenDate as string.
ZurdoDev 25-Nov-13 7:40am    
This is not very clear. What exactly is your issue?

1 solution

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


SQL
--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)"
 
Share this answer
 
Comments
kool15th 26-Nov-13 3:12am    
Thanks samit, but still the flag's value is coming false while I have a record in varchar in database for today. the flag's value should be true if the values matched. CardId is working properly so the problem is only with date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900