Ejemplo n.º 1
0
        public void UpdateGridView()
        {
            try
            {
                conn.Open();
                cmd = new SqlCommand(sqladd, conn);
                cmd.Parameters.Add("@PokehunterID", SqlDbType.Int).Value = int.Parse(Session["PokehunterID"].ToString());
                rdr = cmd.ExecuteReader();

                GridViewCatch.DataSource = rdr;
                GridViewCatch.DataBind();
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message;
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }

            try
            {
                conn.Open();
                cmd = new SqlCommand("SELECT * FROM Pokemons", conn);
                cmd.Parameters.Add("@PokehunterID", SqlDbType.Int).Value = int.Parse(Session["PokehunterID"].ToString());
                rdr = cmd.ExecuteReader();

                DropDownListPokemons.DataSource     = rdr;
                DropDownListPokemons.DataTextField  = "PokemonName";
                DropDownListPokemons.DataValueField = "PokemonNumber";
                DropDownListPokemons.DataBind();
                DropDownListPokemons.Items.Insert(0, "Select a Pokemon to catch");
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message;
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateGridView()
        {
            SqlConnection conn = new SqlConnection(@"data source = .\SQLEXPRESS; integrated security = true; database = Pokemons");

            string sqlsel = "SELECT * FROM Pokemons";

            try
            {
                da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand(sqlsel, conn);

                ds = new DataSet();
                da.Fill(ds, "MyPokemons");
                dt = ds.Tables["MyPokemons"];

                GridViewDelete.DataSource = dt;
                GridViewDelete.DataBind();

                DropDownListPokemons.DataSource     = dt;
                DropDownListPokemons.DataTextField  = "PokemonName";
                DropDownListPokemons.DataValueField = "PokemonNumber";
                DropDownListPokemons.DataBind();
                DropDownListPokemons.Items.Insert(0, "Select pokémon to delete");
            }
            catch (Exception ex)
            {
                LabelMessage.Text = ex.Message;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }