Exemplo n.º 1
0
        public void crearPlatoDeComida(PlatoDeComida platoDeComida)
        {
            using (var conn = new SqlConnection(this.CONECCION_STRING)) {
                conn.Open();

                // 1.  create a command object identifying the stored procedure
                SqlCommand cmd = new SqlCommand("dbo.crearPlatoDeComida", conn);

                // 2. set the command object so it knows to execute a stored procedure
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add(new SqlParameter("@nombrePlato", platoDeComida.obtenerNombrePlato()));
                cmd.Parameters.Add(new SqlParameter("@precioPlato", platoDeComida.obtenerValorPlato()));

                // execute the command
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    // iterate through results, printing each to console
                    while (rdr.Read())
                    {
                        Console.WriteLine("Product: {0,-35} Total: {1,2}", rdr["nombrePlato"], rdr["precioPlato"]);
                    }
                }

                conn.Close();
            }
        }
Exemplo n.º 2
0
 public int registrarPlato(PlatoDeComida plato)
 {
     consultaString = "insert into PlatoDeComida (nombrePlato,precioPlato,tipoPlato,activoPlato )" +
                      " values ('" + plato.obtenerNombrePlato() + "', '" + plato.obtenerValorPlato() + "', '" + plato.obtenerTipo() + "', 'Si'  );";
     coneccion = new SqlConnection(CONECCION_STRING);
     coneccion.Open();
     if (coneccion.State == System.Data.ConnectionState.Open)
     {
         comandoQuery = new SqlCommand(consultaString, coneccion);
         int i = Convert.ToInt16(comandoQuery.ExecuteNonQuery());
         coneccion.Close();
         return(i);
     }
     return(-1);
 }