//往数据库中添加赛事,并且返回新被添加的赛事 public static SeasonMatch addNewMatch(string name,string description,int switchNum,int serialNum) { SeasonMatch match = new SeasonMatch(); DBUtility dbutility = new DBUtility(); int matchID; string SQL = "insert into matchinfo(seasonName,description,switchNum,serialNum) values('"; SQL=SQL+name + "','" + description + "'," + switchNum + "," + serialNum + ")"; try { dbutility.openConnection(); matchID = dbutility.ExecuteQuery_Last_Insert_ID(SQL); // dbutility.ExecuteUpdate(SQL); match.setID(matchID); match.setName(name); match.setDescription(description); match.setSwitchNum(switchNum); match.setSerialNum(serialNum); } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } return match; }
//依据赛事名称,返回赛事信息 public static SeasonMatch getMatchInfo(string matchName) { SeasonMatch match = new SeasonMatch(); //执行查询数据库操作 DBUtility dbutility = new DBUtility(); string SQL = "select ID,seasonName,description,switchNum,serialNum from matchinfo where seasonName='" + matchName + "'"; try { dbutility.openConnection(); MySqlDataReader rd = dbutility.ExecuteQuery(SQL); while (rd.Read()) { match.setID(Convert.ToInt32(rd[0])); match.setName(Convert.ToString(rd[1])); match.setDescription(Convert.ToString(rd[2])); match.setSwitchNum(Convert.ToInt32(rd[3])); match.setSerialNum(Convert.ToInt32(rd[4])); } } catch (MySqlException ex) { Console.WriteLine(ex.ToString()); } finally { dbutility.Close(); } return match; }