1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
   |  
    protected void Confirmer_Click(object sender, EventArgs e)
    {
        int CodeCategorie = int.Parse(DdlCategorie.SelectedValue);
        Book NewBook = new Book(TxtIsbn.Text
                                , TxtTitre.Text
                                , TxtAuteur.Text
                                , int.Parse(DdlCategorie.SelectedValue)
                                , decimal.Parse(TxtPrix.Text)
                                , int.Parse(TxtCD.Text)
                                , DateTime.Parse(TxtParution.Text)
                                , int.Parse(TxtPage.Text)
                                );
 
        if (Page.IsValid)
        {
 
            SqlConnection myConnection = new SqlConnection();
 
 
            myConnection.ConnectionString = "Data Source=PC-LAURENCE\\SQLEXPRESS; Initial Catalog=Librarie; Integrated Security=True;";
            myConnection.Open();
 
            // Requete SQL
            SqlCommand myCommande;
            myCommande = new SqlCommand("Insert INTO Ouvrages (ISBN, Titre, Auteur, Catégorie, Prix, CD, DateParution, NbPages) VALUES('" + TxtIsbn.Text + "', '" + TxtTitre.Text + "', '" + TxtAuteur.Text + "','" + DdlCategorie.SelectedValue + "','" + decimal.Parse(TxtPrix.Text) + "', '" + int.Parse(TxtCD.Text) + "', '" + DateTime.Parse(TxtParution.Text) + "', '" + int.Parse(TxtPage.Text) + "')", myConnection);
            myCommande.ExecuteReader();
        }
 
    }
    void ChargerListeCategorie()
    {
 
        SqlConnection myConnection = new SqlConnection();
 
 
        myConnection.ConnectionString = "Data Source=PC-LAURENCE\\SQLEXPRESS; Initial Catalog=Librarie; Integrated Security=True;";
        myConnection.Open();
 
        // Requete SQL
        SqlCommand myCommande;
        myCommande = new SqlCommand("SELECT Categorie, Code_Categorie from Categorie", myConnection);
        SqlDataReader lecteurCategorie = myCommande.ExecuteReader();
 
 
        List<Categorie> Categories = new List<Categorie>();
        while (lecteurCategorie.Read())
        {
            Categories.Add(new Categorie(lecteurCategorie["Categorie"].ToString(), int.Parse(lecteurCategorie["Code_Categorie"].ToString())));
        }
        DdlCategorie.DataSource = Categories;
        DdlCategorie.DataTextField = "CategorieTitle";
        DdlCategorie.DataValueField = "Code_Categorie";
 
        DdlCategorie.DataBind();
 
        lecteurCategorie.Close();
        myConnection.Close();
 
    } |