コード例 #1
0
        // INSERT
        public string Create(DB_articulos_presentacion PresentacionNew)
        {
            string        respuesta = "";
            SqlConnection SQL       = new SqlConnection();

            try
            {
                // Conexion
                SQL.ConnectionString = ConexionDB.StringConection;
                SQL.Open();

                // Establecer Procedimiento
                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection  = SQL;                         // Heredar conexion
                SQL_comando.CommandText = "POST_presentacion";         // comando de procedimiento almacenado
                SQL_comando.CommandType = CommandType.StoredProcedure; // Indicamos que es un procedimiento almacenado

                // Creamos parametros de ejecucion SQL
                SqlParameter PRESENTACION = new SqlParameter();         // instanciamos
                PRESENTACION.ParameterName = "@presentacion_id";        // nombre de variable
                PRESENTACION.SqlDbType     = SqlDbType.Int;             // tipo de variable
                PRESENTACION.Direction     = ParameterDirection.Output; // formato de entrada / salida
                SQL_comando.Parameters.Add(PRESENTACION);               // Añadimos al comando

                SqlParameter NOMBRE = new SqlParameter();               // instanciamos
                NOMBRE.ParameterName = "@presentacion_nombre";          // nombre de variable
                NOMBRE.SqlDbType     = SqlDbType.VarChar;               // tipo de variable
                NOMBRE.Size          = 150;
                NOMBRE.Value         = PresentacionNew.Presentacion_nombre;
                SQL_comando.Parameters.Add(NOMBRE);                                   // Añadimos al comando

                SqlParameter DESCRIPCION = new SqlParameter();                        // instanciamos
                DESCRIPCION.ParameterName = "@presentacion_descripcion";              // nombre de variable
                DESCRIPCION.SqlDbType     = SqlDbType.Text;                           // tipo de variable
                DESCRIPCION.Size          = 500;
                DESCRIPCION.Value         = PresentacionNew.Presentacion_descripcion; // valor de la variable
                SQL_comando.Parameters.Add(DESCRIPCION);                              // Añadimos al comando

                // Ejecutar consulta
                respuesta = SQL_comando.ExecuteNonQuery() == 1 || true ? "Realizado Exitosamente" : "Error al guardar la presentacion de plato";
            }
            catch (Exception error)
            {
                respuesta = error.Message;
                throw;
            }
            finally
            {
                // Cerramos la conexion
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(respuesta);
        }
コード例 #2
0
        // GET ID
        public DataTable GetDetalleID(DB_articulos_presentacion PresentacionID)
        {
            string        respuesta       = "";
            DataTable     AllPresentacion = new DataTable("presentacion");
            SqlConnection SQL             = new SqlConnection();

            try
            {
                SQL.ConnectionString = ConexionDB.StringConection;
                SqlCommand SQL_comando = new SqlCommand();
                SQL_comando.Connection = SQL;

                SQL_comando.CommandText = "GET_ID_presentacion";
                SQL_comando.CommandType = CommandType.StoredProcedure;

                SqlParameter PRESENTACION = new SqlParameter();
                PRESENTACION.ParameterName = "@idpresentacion";
                PRESENTACION.SqlDbType     = SqlDbType.Int;
                PRESENTACION.Size          = 256;
                PRESENTACION.Value         = PresentacionID.Presentacion_id;
                SQL_comando.Parameters.Add(PRESENTACION);

                SqlDataAdapter RespuestaSQL = new SqlDataAdapter(SQL_comando);
                RespuestaSQL.Fill(AllPresentacion);
            }
            catch (Exception error)
            {
                respuesta       = error.Message;
                AllPresentacion = null;
                throw;
            }
            finally
            {
                if (SQL.State == ConnectionState.Open)
                {
                    SQL.Close();
                }
            }
            return(AllPresentacion);
        }