public static int DoEnterAttendance(AttendanceInfo NewAttendance) { int returnVal = 0; MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); //define the connection used by the command object msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "INSERT INTO attendance(id,atnddate,stuname,tchrname,stuclass,present) " + "VALUES(@id,@atnddate,@stuname,@tchrname,@stuclass,@present)"; msqlCommand.Parameters.AddWithValue("@id", NewAttendance.id); msqlCommand.Parameters.AddWithValue("@atnddate", NewAttendance.atnddate); msqlCommand.Parameters.AddWithValue("@stuname", NewAttendance.stuname); msqlCommand.Parameters.AddWithValue("@tchrname", NewAttendance.tchrname); msqlCommand.Parameters.AddWithValue("@stuclass", NewAttendance.stuclass); msqlCommand.Parameters.AddWithValue("@present", NewAttendance.present); msqlCommand.ExecuteNonQuery(); returnVal = 1; } catch (Exception er) { returnVal = 0; } finally { //always close the connection msqlConnection.Close(); } return returnVal; }
public static List<AttendanceInfo> GetAllAttendanceList() { List<AttendanceInfo> AttendanceList = new List<AttendanceInfo>(); MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "Select * From attendance ;"; MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); while (msqlReader.Read()) { AttendanceInfo Attendance = new AttendanceInfo(); Attendance.id = msqlReader.GetString("id"); Attendance.atnddate = msqlReader.GetDateTime("atnddate"); Attendance.stuname = msqlReader.GetString("stuname"); Attendance.tchrname = msqlReader.GetString("tchrname"); Attendance.stuclass = msqlReader.GetString("stuclass"); Attendance.present = msqlReader.GetString("present"); AttendanceList.Add(Attendance); } } catch (Exception er) { } finally { //always close the connection msqlConnection.Close(); } return AttendanceList; }