Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to save login and logout time of user in the databse.I am able to save login time.I want if user has logged in once there should not be duplicate entry on whole particular date. following are my sql coding and c# coding can any one help me..
thanx in advance
my sql table structure is as follows
SQL
create table EmpAttendance
(
    AttendenceID int primary key ,
    EmpID nvarchar(10) foreign key references Employee(EmpID),
    LoginTime datetime,
    LogoutTime datetime,
    AttDate datetime
)

And C# coding are..
C#
DataSet ds1 = obj.CheckAttendance(Session["EmpID"].ToString(), (DateTime.Now).ToString());

if (ds1.Tables[0].Rows.Count > 0)
{
    //Response.Write("hiiiiii");
}
else
{
    obj.InsAttendance(Session["EmpID"].ToString(), (DateTime.Now).ToString(), "", (DateTime.Now).ToString());
    // Response.Write("hiiiiii");
}

every time only else part is running.....i want that else part should run only when there is no entry.....


[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2

1 solution

That is because you are checking with (DateTime.Now).ToString(), which will be different always as it is a DateTime value, not Date only.

To get Date only, you have to store the Date only and compare that.
You can use DateTime.Now.ToString("M/d/yyyy");.

But make sure, while storing, you also store Date in this format.

To know more on formats, see - Custom Date and Time Format Strings[^].
 
Share this answer
 
v2

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