コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Country GetCountry(int id)
        {
            MySqlManager  db      = new MySqlManager(DbConnectionString);
            StringBuilder sbQuery = new StringBuilder();
            Country       country = new Country();

            try
            {
                sbQuery.Append("select ")
                .Append("Id, ")
                .Append("NameEn, ")
                .Append("NameEs, ")
                .Append("ISO2, ")
                .Append("ISO3 ")
                .Append("from country ")
                .Append("where Id = ").Append(id);

                if (db.Open() == true)
                {
                    MySqlDataReader reader = db.ExecuteReader(CommandType.Text, sbQuery.ToString());
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            country = new Country
                            {
                                Id     = Convert.ToInt32(reader["Id"].ToString()),
                                NameEn = reader["NameEn"].ToString(),
                                NameEs = reader["NameEs"].ToString(),
                                ISO2   = reader["ISO2"].ToString(),
                                ISO3   = reader["ISO3"].ToString()
                            };
                        }
                    }
                    else
                    {
                        country = null;
                    }
                    reader.Close();
                    db.Close();
                }
                else
                {
                    // Error at Connect to SQL-Server Server
                    ErrorMessage = db.ErrorMessage;
                    return(null);
                }
                return(country);
            }
            catch
            {
                ErrorMessage = db.ErrorMessage;
                return(null);
            }
        }
コード例 #2
0
        public int InsertCountry(Country data)
        {
            MySqlManager  db      = new MySqlManager(DbConnectionString);
            StringBuilder sbQuery = new StringBuilder();
            int           nRows   = 0;

            try
            {
                DataTable dtParameters = db.ConfigTableForParameters();
                dtParameters.Rows.Add("@NameEn", data.NameEn, MySqlDbType.VarChar);
                dtParameters.Rows.Add("@NameEs", data.NameEs, MySqlDbType.VarChar);
                dtParameters.Rows.Add("@ISO2", data.ISO2, MySqlDbType.VarChar);
                dtParameters.Rows.Add("@ISO3", data.ISO3, MySqlDbType.VarChar);

                string query = db.InsertQueryBuilder("soundbeats.country", dtParameters);

                // Apertura de conexión
                if (db.Open())
                {
                    db.TableAddInParameters(dtParameters);
                    nRows = db.ExecuteNonQuery(CommandType.Text, query);
                    if (nRows == -1)
                    {
                        ErrorMessage = db.ErrorMessage;
                    }
                    db.Close();
                }
                else
                {
                    // Error at Connect to SQL-Server Server
                    ErrorMessage = db.ErrorMessage;
                    return(-1);
                }
            }
            catch
            {
                ErrorMessage = db.ErrorMessage;
                return(-1);
            }
            return(nRows);
        }
コード例 #3
0
        public int InsertCountryNoParametrics(Country data)
        {
            MySqlManager  db      = new MySqlManager(DbConnectionString);
            StringBuilder sbQuery = new StringBuilder();
            int           nRows   = 0;

            try
            {
                // INSERT INTO soundbeats.country(NameEn, NameEs, ISO2, ISO3)
                // VALUES('Greece', 'Grecia', 'GR', 'GRC')
                sbQuery.Append("INSERT INTO soundbeats.country(NameEn, NameEs, ISO2, ISO3) ")
                .Append("VALUES(")
                .Append("'").Append(data.NameEn).Append("', ")
                .Append("'").Append(data.NameEs).Append("', ")
                .Append("'").Append(data.ISO2).Append("', ")
                .Append("'").Append(data.ISO3).Append("') ");
                // Apertura de conexión
                if (db.Open())
                {
                    nRows = db.ExecuteNonQuery(CommandType.Text, sbQuery.ToString());
                    if (nRows == -1)
                    {
                        ErrorMessage = db.ErrorMessage;
                    }
                    db.Close();
                }
                else
                {
                    // Error at Connect to SQL-Server Server
                    ErrorMessage = db.ErrorMessage;
                    return(-1);
                }
            }
            catch
            {
                ErrorMessage = db.ErrorMessage;
                return(-1);
            }
            return(nRows);
        }
コード例 #4
0
        public int InsertMusician(Musician data)
        {
            MySqlManager db    = new MySqlManager(DbConnectionString);
            int          nRows = 0;

            try
            {
                DataTable dtParameters = db.ConfigTableForParameters();
                dtParameters.Rows.Add("@FirstName", data.FirstName, MySqlDbType.VarChar);
                dtParameters.Rows.Add("@LastName", data.LastName, MySqlDbType.VarChar);
                dtParameters.Rows.Add("@BirthDate", data.BirthDate.ToString("yyyy-MM-dd HH:mm:ss"), MySqlDbType.DateTime);
                dtParameters.Rows.Add("@BirthPlace", data.BirthPlace, MySqlDbType.VarChar);

                string query = db.InsertQueryBuilder("soundbeats.musician", dtParameters);

                // Apertura de conexión
                if (db.Open())
                {
                    db.TableAddInParameters(dtParameters);
                    nRows = db.ExecuteNonQuery(CommandType.Text, query);
                    if (nRows == -1)
                    {
                        ErrorMessage = db.ErrorMessage;
                    }
                    db.Close();
                }
                else
                {
                    // Error at Connect to SQL-Server Server
                    ErrorMessage = db.ErrorMessage;
                    return(-1);
                }
            }
            catch
            {
                ErrorMessage = db.ErrorMessage;
                return(-1);
            }
            return(nRows);
        }