Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 how to save the login time and logout time in text file using with c# with sql server
Posted by charan on  3/16/2010 3:36:03 AM Category: ADO.NET
Add to my favorites
Email to friend
hi i have table fields in sql server 2000

username nvarchar
password nvarchar

logintime datetime
logouttime datetime
hoursspend int

i want to save into text file when ever user login and logout any no of times and finally i want to know how many hours he spend in a day. can you give me a example which helps me

Post Your Reply Post New Question

 Viewer's Reply
Create, Write and Append Text in Files with Asp.Net
Answered By Moderator1 on 3/20/2010 10:54:55 PM

I hope you know how to retrieve those login information from the database. You need to keep the details as a DataTable Rows. Then for creating a Text File and writing the content into it follow the code below,

string strFilePath = Server.MapPath(@".\LoginLog.txt");

using (StreamWriter sw = new StreamWriter(strFilePath, true))
sw.WriteLine("User Name: " + dr["UserName"].ToString());
sw.WriteLine("Login Time: " + dr["LoginTime"].ToString());
sw.WriteLine("Logout Time: " + dr["LogoutTime"].ToString());

To calculating the Hours spend, write you own logic.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Washington Technology
Easing the Migration to Microsoft SQL Server 2005
Everything You Know About CSS Is Wrong! - Free 37 Page Preview!