DateTime nowdate=DateTime. Now. The Date;
String sql_date=the string. Format (" select count (Timedate) as counttime from attendance records where YGID='{0}' and Timedate='{1} ", number, nowdate);
Using (SqlConnection conndate=new SqlConnection (connString))
{
SqlCommand commdate=new SqlCommand (SQL, conn);
Int countdate=(int) commdate. ExecuteScalar ();
If (countdate & gt; 0)
{
MessageBox. Show (" you have been signed in today, please don't repeat sign in!" );
return;
}
CodePudding user response:
You to determine that day. You must want to format the time.
Select count (1) the from to have the where the convert (varachar (10), time, 21)='2012-12-12'
CodePudding user response:
SqlCommand commdate=new SqlCommand (SQL, conn);This sentence is modified to SqlCommand commdate=new SqlCommand (sql_date, conn);
I defined in the SQL table for timedate as datetime class, but just want to compare the date, don't need specific time how to implement, the code I wrote above, there is a problem, can still sign in many times on the same day when actual operation