public List <Labourer> getAllLabourer(MySqlConnection conn) { List <Labourer> listOfLab = new List <Labourer>(); // get from table // add to list string sql = "SELECT * FROM labourer "; MySqlCommand sqlComm = new MySqlCommand(sql, conn); //try //{ MySqlDataReader reader; reader = sqlComm.ExecuteReader(); while (reader.Read()) { Labourer aLabr = new Labourer(); aLabr.Id = (int)reader.GetValue(0); aLabr.Name = (string)reader.GetValue(1); aLabr.Age = (int)reader.GetValue(2); aLabr.Gender = (string)reader.GetValue(3); listOfLab.Add(aLabr); } //} //finally //{ //} // return the list return(listOfLab); }
public int addNewLabourer(MySqlConnection conn, Labourer labourer) { string sql = "INSERT INTO labourer (name, age, gender) " + " VALUES ('" + labourer.Name + "', " + labourer.Age + ", '" + labourer.Gender + "')"; MySqlCommand sqlComm = new MySqlCommand(sql, conn); return(sqlComm.ExecuteNonQuery()); }
private void button7_Click(object sender, EventArgs e) { DBConnector dbConn = new DBConnector(); dbConn.connect(); Labourer labr = new Labourer(); labr.Name = textBox6.Text; labr.Age = int.Parse(textBox7.Text); labr.Gender = textBox8.Text; LabourerHandler labHnd = new LabourerHandler(); int recordCnt = labHnd.addNewLabourer(dbConn.getConn(), labr); MessageBox.Show(recordCnt + " record has been inserted !!"); }