コード例 #1
0
        //Just added this
        public List <Labourer> getAllLabourer(MySqlConnection conn)
        {
            List <Labourer> listLabr = new List <Labourer>();

            string sql = "SELECT * FROM labourer WHERE 1";

            MySqlCommand sqlComm = new MySqlCommand(sql, conn);

            //try
            //{
            MySqlDataReader myReader;

            myReader = sqlComm.ExecuteReader();

            while (myReader.Read())
            {
                Labourer aLabr = new Labourer();
                aLabr.Id   = (int)myReader.GetValue(0);
                aLabr.Name = (string)myReader.GetValue(1);
                aLabr.Age  = (int)myReader.GetValue(2);


                listLabr.Add(aLabr);
            }
            //}
            return(listLabr);
        }
コード例 #2
0
        public int addNewLabourer(MySqlConnection conn, Labourer labourer)
        {
            string sql = "INSERT INTO labourer (name, age, gender, dateAndTime) "
                         + " VALUES ('" + labourer.Name + "', " + labourer.Age
                         + " , '" + labourer.Gender + "', '" + labourer.DateAndTime + "')";

            MySqlCommand sqlComm = new MySqlCommand(sql, conn);

            return(sqlComm.ExecuteNonQuery());
        }
コード例 #3
0
        private void button7_Click(object sender, EventArgs e)
        {
            DbConnector dbConn = new DbConnector();

            dbConn.connect();

            Labourer labr = new Labourer();

            labr.Name        = textBoxName;
            labr.Age         = textBoxAge;
            labr.Gender      = textBoxGender;
            labr.DateAndTime = dateAndTime;

            LabourerHandler labHnd    = new LabourerHandler();
            int             recordCnt = labHnd.addNewLabourer(dbConn.getConn(), labr);

            MessageBox.Show(recordCnt + " record has been inserted !!");
        }