public void loadDataOfDatagridView() { //先清除dataGridView中的数据 if (this.dataGridView_playerManage.Rows.Count > 0) { dataGridView_playerManage.Rows.Clear(); } //取出数据 List<FootballPlayer> list = ContentDAO.getPlayerInfoOfCertainTeam(selectedTeamName); for (int i = 0; i < list.Count;i++ ) { player = list[i]; dataGridView_playerManage.Rows.Add(player.getID(),player.getName(),player.getNumber(),player.getNumber().ToString(),player.getPostion(),player.getBelongTeam(),player.getIDnum()); } }
//往数据库中添加球员,返回是否添加成功的信息 public static bool addNewPlayer(FootballPlayer player) { DBUtility dbutility = new DBUtility(); string SQL = "insert into player(playerName,postion,teamName,number,playerIDnum) values('"; SQL = SQL + player.getName() + "','" + player.getPostion() + "','" + player.getBelongTeam() + "'," + player.getNumber() + ",'" +player.getIDnum() + "')"; try { dbutility.openConnection(); dbutility.ExecuteUpdate(SQL); return true; } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); return false; } finally { dbutility.Close(); } }