示例#1
0
        // METODOS PROPIOS


        public string Insertar(D_categoria categoria)
        {
            string          rspt     = "";
            MySqlConnection conexion = new MySqlConnection();

            try
            {
                /// creo conexion
                conexion.ConnectionString = Conexion.Cn;
                conexion.Open();

                /// configuro parametros
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conexion;
                cmd.CommandText = "SP_INSERTAR_CATEGORIA";
                cmd.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametro_nombre = new MySqlParameter();
                parametro_nombre.ParameterName = "NOMBRE";
                parametro_nombre.MySqlDbType   = MySqlDbType.VarChar;
                parametro_nombre.Value         = categoria.Nombre;

                MySqlParameter parametro_descripcion = new MySqlParameter();
                parametro_descripcion.ParameterName = "DESCRIPCION";
                parametro_descripcion.MySqlDbType   = MySqlDbType.VarChar;
                parametro_descripcion.Value         = categoria.Descripcion;



                cmd.Parameters.Add(parametro_nombre);
                cmd.Parameters.Add(parametro_descripcion);



                // ejecutamos
                if (cmd.ExecuteNonQuery() == 1)
                {
                    rspt = "Ok";
                }
                else
                {
                    rspt = "NO SE HA PODIDO INSERTAR";
                }
            }
            catch (Exception ex)
            {
                rspt = ex.Message;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
            }

            return(rspt);
        }
示例#2
0
        public string Eliminar(D_categoria categoria)
        {
            string          rspt     = "";
            MySqlConnection conexion = new MySqlConnection();

            try
            {
                /// creo conexion
                conexion.ConnectionString = Conexion.Cn;
                conexion.Open();

                /// configuro parametros
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conexion;
                cmd.CommandText = "SP_ELIMINAR_CATEGORIA";
                cmd.CommandType = CommandType.StoredProcedure;

                MySqlParameter parametro_categoria = new MySqlParameter();
                parametro_categoria.ParameterName = "_ID_CATEGORIA";
                parametro_categoria.MySqlDbType   = MySqlDbType.Int32;
                parametro_categoria.Value         = categoria.Id_categoria;

                cmd.Parameters.Add(parametro_categoria);



                // ejecutamos
                if (cmd.ExecuteNonQuery() == 1)
                {
                    rspt = "Ok";
                }
                else
                {
                    rspt = "NO SE HA PODIDO ELIMINAR";
                }
            }
            catch (Exception ex)
            {
                rspt = ex.Message;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
            }

            return(rspt);
        }