示例#1
0
        public static Band Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM bands WHERE id = (@searchId);";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            var  rdr     = cmd.ExecuteReader() as MySqlDataReader;
            Band newBand = new Band("", "", "", "", "", "", "", "");

            while (rdr.Read())
            {
                newBand.SetId(rdr.GetInt32(0));
                newBand.SetName(rdr.GetString(1));
                newBand.SetGenre(rdr.GetString(2));
                newBand.SetLeader(rdr.GetString(3));
                newBand.SetMembers(rdr.GetString(4));
                newBand.SetOriginPlace(rdr.GetString(5));
                newBand.SetOriginYear(rdr.GetString(6));
                newBand.SetAgent(rdr.GetString(7));
                newBand.SetAgentContact(rdr.GetString(8));
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            return(newBand);
        }