Esempio n. 1
0
        public Avion buscarAvionPorId(int id)
        {
            Avion av = null;
            MyConnection myConnection = new MyConnection();
            SqlConnection conexion = myConnection.CreateConnection();
            SqlCommand comando = myConnection.CreateCommand(conexion);
            SqlDataReader al;

            comando.CommandText = "sp_searchByIdPlane";
            comando.CommandType = CommandType.StoredProcedure;
            comando.Parameters.AddWithValue("@pId ", id);
            try
            {
                conexion.Open();
                al = comando.ExecuteReader();
                while (al.Read())
                {
                    av = new Avion();
                    av.IdAvion = (int)al["idAvion"];
                    av.Marca = (string)al["marca"];
                    av.Asientos = (int)al["cantidadAsientos"];
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
            return av;
        }
Esempio n. 2
0
        public List<Avion> listarAviones()
        {
            List<Avion> listaavion = new List<Avion>();
            MyConnection myConnection = new MyConnection();
            SqlConnection conexion = myConnection.CreateConnection();
            SqlCommand comando = myConnection.CreateCommand(conexion);
            SqlDataReader pl;

            comando.CommandText = "sp_listPlane";
            comando.CommandType = CommandType.StoredProcedure;
            try
            {
                conexion.Open();
                pl = comando.ExecuteReader();
                while (pl.Read())
                {
                    Avion creaavion = new Avion();
                    creaavion.IdAvion = (int)pl["idAvion"];
                    creaavion.Marca = (string)pl["marca"];
                    creaavion.Asientos = (int)pl["cantidadAsientos"];

                    listaavion.Add(creaavion);

                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conexion.Close();
            }
            return listaavion;
        }
        //*creaavion
        public Avion buscarAvionPorId(int id)
        {
            Avion av = new Avion();
            MyConnection myConnection = new MyConnection();
            DataContext datacontext = new DataContext(myConnection.SQLConnection);
            var table = datacontext.GetTable<Avion>();

            try
            {
                var listaAvion = from lt in table
                                 where lt.IdAvion == id
                                 select lt;
                foreach (Avion b in listaAvion)
                {
                    av = b;
                }

                /*SqlConnection conexion = myConnection.CreateConnection();
                SqlCommand comando = myConnection.CreateCommand(conexion);
                SqlDataReader al;

                comando.CommandText = "sp_searchByIdPlane";
                comando.CommandType = CommandType.StoredProcedure;
                comando.Parameters.AddWithValue("@pId ", id);
                try
                {
                    conexion.Open();
                    al = comando.ExecuteReader();
                    while (al.Read())
                    {
                        av = new Avion();
                        av.IdAvion = (int)al["idAvion"];
                        av.Marca = (string)al["marca"];
                        av.Asientos = (int)al["cantidadAsientos"];
                    }
                }
                catch (SqlException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    conexion.Close();
                }
                return av;*/
            }

            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }

            return av;
        }