Overview
In enterprise attendance systems, especially those utilizing facial recognition, accurate data logging and timely exports are vital. In this article, we’ll walk through a real-world Windows Forms application that automatically fetches employee attendance data and exports it as a CSV file using AppBlock’s SqlHelper, with built-in error and process logging.
Key Functionalities
1. Form Timer + Manual Button Trigger
The application allows automated and manual execution of log processing.
timer1_Tick => CSVFiles();
button1_Click => CSVFiles();
This gives flexibility to either schedule or manually trigger data exports.
2. Error Logging Functionality
All exceptions are logged into a daily log file for easy debugging.
public void ErrorLog(string log)
{
// Add your error logging logic here
}
- Log Path: /ErrorLog/
- File: ddMMyy.txt
Each log entry includes.
- Timestamp
- Error message
- Separator line
3. Process Logging
Process milestones are written into a separate log file.
public void ProcessLog(string log)
{
// Your implementation here
}
- Log Path: /ProcessLog/
- File: ddMMyy.txt
This helps trace successful updates, such as which record (sno) was processed.
4. Data Extraction from SQL Server
Using AppBlock’s SqlHelper, the app connects to SQL Server and fetches logs from the LogTable and EmployeeDetails.
string qry = "SELECT b.payrollid, a.ID, ...";
DataSet ds = SqlHelper.ExecuteDataset(...);
Data includes: PayrollID, Name, LoginTime, LogoutTime, LogID, and more.
The connection string is loaded via.
ConfigurationManager.ConnectionStrings["Signin"].ToString();
5. CSV Export with Timestamped Filenames
The data is exported as a timestamped CSV file for easy tracking.
string filePath = Path.Combine(
source + "/File/",
"Face_" + DateTime.Now.ToString("ddMMyyyy_HHmm") + ".csv"
);
File.WriteAllText(
filePath,
csvContent.ToString(),
Encoding.UTF8
);
- Folder: /File/
- Filename: Face_ddMMyyyy_HHmm.csv
The use of Encoding.UTF-8 ensures compatibility across systems.
6. Time-Based Data Processing
The application checks for conditions based on current time and stored time/date values before exporting.
if (DateTime.Now.Date > tbleDate && tbleTime <= currentTime)
{
// Your logic here
}
Once processed, the tbleDate is updated.
UPDATE signin_Timer
SET tbleDate = GETDATE()
WHERE sno = ...;

Join the conversation! Your thoughts help the community grow.