Esempio n. 1
0
 //依据球员的姓名,返回球员信息
 public static FootballPlayer getPlayerInfo(string playerName)
 {
     FootballPlayer player = new FootballPlayer();
     //执行查询数据库操作
     DBUtility dbutility = new DBUtility();
     string SQL = "select ID,playerName,number,postion,teamName from player where playerName='" + playerName+"'";
     try
     {
         dbutility.openConnection();
         MySqlDataReader rd = dbutility.ExecuteQuery(SQL);
         while (rd.Read())
         {
             player.setPlayerID(Convert.ToInt32(rd[0]));
             player.setPlayerName(Convert.ToString(rd[1]));
             player.setPlayNumber(Convert.ToInt32(rd[2]));
             player.setPostion(Convert.ToString(rd[3]));
             player.setBelongTeam(Convert.ToString(rd[4]));
         }
     }
     catch (MySqlException ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         dbutility.Close();
     }
     return player;
 }