//retrive bay name public string getBayName(MySqlConnection conn, string bayN) { CentralStation centralStation = new CentralStation(); string bayName; string sql = "SELECT * FROM centralstation where centralStationName='" + bayN + "'"; MySqlCommand sqlComm = new MySqlCommand(sql, conn); try { MySqlDataReader myReader; myReader = sqlComm.ExecuteReader(); if (myReader.Read()) { centralStation.Id = (int)myReader.GetValue(0); centralStation.CentralStationName = (string)myReader.GetValue(1); } myReader.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } bayName = centralStation.CentralStationName; return(bayName); }
//list centralstation public List <CentralStation> getAllCentralStation(MySqlConnection conn) { List <CentralStation> listCentralStation = new List <CentralStation>(); string sql = "SELECT * FROM centralstation"; MySqlCommand sqlComm = new MySqlCommand(sql, conn); try { MySqlDataReader myReader; myReader = sqlComm.ExecuteReader(); while (myReader.Read()) { CentralStation centralStation = new CentralStation(); centralStation.Id = (int)myReader.GetValue(0); centralStation.CentralStationName = (string)myReader.GetValue(1); listCentralStation.Add(centralStation); } myReader.Close(); } catch (Exception e) { Console.WriteLine(e.ToString()); } return(listCentralStation); }