gregory8500 | bonjour, j'ai un probleme, avec mon programme je dois avoir acces a une base de donne, la lire et ecrire dedans, les 2 premiers ne me pose pas de probleme
Code :
- #pragma once
- #include <string.h>
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- namespace librairie {
- /// <summary>
- /// Description résumée de rechercher
- ///
- /// AVERTISSEMENT : si vous modifiez le nom de cette classe, vous devrez modifier la
- /// propriété 'Nom du fichier de ressources' de l'outil de compilation de ressource managée
- /// pour tous les fichiers .resx dont dépend cette classe. Dans le cas contraire,
- /// les concepteurs ne pourront pas interagir correctement avec les ressources
- /// localisées associées à ce formulaire.
- /// </summary>
- public ref class rechercher : public System::Windows::Forms::Form
- {
- public:
- rechercher(void)
- {
- this->BaseDonnee = (gcnew System::Data::OleDb::OleDbConnection());
- InitializeComponent();
- //
- //TODO : ajoutez ici le code du constructeur
- //
- }
- protected:
- /// <summary>
- /// Nettoyage des ressources utilisées.
- /// </summary>
- ~rechercher()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Data::OleDb::OleDbConnection^ BaseDonnee;
- private: System::Data::OleDb::OleDbConnection^ BaseDeDonnee;
- private: System::Windows::Forms::Button^ rechercherbt;
- private: System::Windows::Forms::Button^ effacer;
- private: System::Windows::Forms::Button^ quitter;
- protected:
- protected:
- private: System::Windows::Forms::CheckBox^ auteurchb;
- private: System::Windows::Forms::CheckBox^ titrechb;
- private: System::Windows::Forms::TextBox^ auteur;
- private: System::Windows::Forms::TextBox^ textBox2;
- private: System::Windows::Forms::Label^ titre;
- private: System::Windows::Forms::Label^ titre2;
- private: System::Windows::Forms::Panel^ panel1;
- private:
- /// <summary>
- /// Variable nécessaire au concepteur.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
- /// le contenu de cette méthode avec l'éditeur de code.
- /// </summary>
- void InitializeComponent(void)
- {this->BaseDeDonnee = (gcnew System::Data::OleDb::OleDbConnection());
- this->rechercherbt = (gcnew System::Windows::Forms::Button());
- this->effacer = (gcnew System::Windows::Forms::Button());
- this->quitter = (gcnew System::Windows::Forms::Button());
- this->auteurchb = (gcnew System::Windows::Forms::CheckBox());
- this->titrechb = (gcnew System::Windows::Forms::CheckBox());
- this->auteur = (gcnew System::Windows::Forms::TextBox());
- this->textBox2 = (gcnew System::Windows::Forms::TextBox());
- this->titre = (gcnew System::Windows::Forms::Label());
- this->titre2 = (gcnew System::Windows::Forms::Label());
- this->panel1 = (gcnew System::Windows::Forms::Panel());
- this->panel1->SuspendLayout();
- this->SuspendLayout();
- //
- // BaseDeDonnee
- //
- this->BaseDeDonnee->ConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=librairie en ligne.mdb";
- //
- // rechercherbt
- //
- this->rechercherbt->Location = System::Drawing::Point(95, 619);
- this->rechercherbt->Name = L"rechercherbt";
- this->rechercherbt->Size = System::Drawing::Size(75, 23);
- this->rechercherbt->TabIndex = 0;
- this->rechercherbt->Text = L"rechercher";
- this->rechercherbt->UseVisualStyleBackColor = true;
- this->rechercherbt->Click += gcnew System::EventHandler(this, &rechercher::rechercherbt_Click);
- //
- // effacer
- //
- this->effacer->Location = System::Drawing::Point(481, 619);
- this->effacer->Name = L"effacer";
- this->effacer->Size = System::Drawing::Size(75, 23);
- this->effacer->TabIndex = 1;
- this->effacer->Text = L"effacer";
- this->effacer->UseVisualStyleBackColor = true;
- //
- // quitter
- //
- this->quitter->Location = System::Drawing::Point(954, 619);
- this->quitter->Name = L"quitter";
- this->quitter->Size = System::Drawing::Size(75, 23);
- this->quitter->TabIndex = 2;
- this->quitter->Text = L"quitter";
- this->quitter->UseVisualStyleBackColor = true;
- this->quitter->Click += gcnew System::EventHandler(this, &rechercher::quitter_Click);
- //
- // auteurchb
- //
- this->auteurchb->AutoSize = true;
- this->auteurchb->Location = System::Drawing::Point(34, 231);
- this->auteurchb->Name = L"auteurchb";
- this->auteurchb->Size = System::Drawing::Size(56, 17);
- this->auteurchb->TabIndex = 3;
- this->auteurchb->Text = L"auteur";
- this->auteurchb->UseVisualStyleBackColor = true;
- //
- // titrechb
- //
- this->titrechb->AutoSize = true;
- this->titrechb->Location = System::Drawing::Point(34, 94);
- this->titrechb->Name = L"titrechb";
- this->titrechb->Size = System::Drawing::Size(43, 17);
- this->titrechb->TabIndex = 4;
- this->titrechb->Text = L"titre";
- this->titrechb->UseVisualStyleBackColor = true;
- //
- // auteur
- //
- this->auteur->BackColor = System::Drawing::SystemColors::InactiveBorder;
- this->auteur->Location = System::Drawing::Point(570, 228);
- this->auteur->Name = L"auteur";
- this->auteur->Size = System::Drawing::Size(187, 20);
- this->auteur->TabIndex = 5;
- //
- // textBox2
- //
- this->textBox2->Location = System::Drawing::Point(570, 94);
- this->textBox2->Name = L"textBox2";
- this->textBox2->Size = System::Drawing::Size(187, 20);
- this->textBox2->TabIndex = 6;
- //
- // titre
- //
- this->titre->AutoSize = true;
- this->titre->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 50, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->titre->Location = System::Drawing::Point(414, 44);
- this->titre->Name = L"titre";
- this->titre->Size = System::Drawing::Size(330, 76);
- this->titre->TabIndex = 7;
- this->titre->Text = L"recherche";
- //
- // titre2
- //
- this->titre2->AutoSize = true;
- this->titre2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->titre2->Location = System::Drawing::Point(135, 156);
- this->titre2->Name = L"titre2";
- this->titre2->Size = System::Drawing::Size(132, 25);
- this->titre2->TabIndex = 8;
- this->titre2->Text = L"recherche par";
- //
- // panel1
- //
- this->panel1->BackColor = System::Drawing::SystemColors::Control;
- this->panel1->Controls->Add(this->titrechb);
- this->panel1->Controls->Add(this->auteurchb);
- this->panel1->Controls->Add(this->auteur);
- this->panel1->Controls->Add(this->textBox2);
- this->panel1->Location = System::Drawing::Point(95, 184);
- this->panel1->Name = L"panel1";
- this->panel1->Size = System::Drawing::Size(905, 370);
- this->panel1->TabIndex = 9;
- //
- // rechercher
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(1131, 676);
- this->Controls->Add(this->titre2);
- this->Controls->Add(this->panel1);
- this->Controls->Add(this->titre);
- this->Controls->Add(this->quitter);
- this->Controls->Add(this->effacer);
- this->Controls->Add(this->rechercherbt);
- this->Name = L"rechercher";
- this->Text = L"rechercher";
- this->panel1->ResumeLayout(false);
- this->panel1->PerformLayout();
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void quitter_Click(System::Object^ sender, System::EventArgs^ e) {
- this->~rechercher();
- }
- private: System::Void rechercherbt_Click(System::Object^ sender, System::EventArgs^ e) {
- //ouverture base de donne
- this->BaseDeDonnee->Open();
- //requete
- System::Data::OleDb::OleDbCommand^ requete = (gcnew System::Data::OleDb::OleDbCommand("select titre from livre where titre= '"+ this->auteur->Text +"' ", this->BaseDeDonnee));
- // Création du conteneur
- System::Data::OleDb::OleDbDataReader^ lecteur;
- lecteur = requete->ExecuteReader();
- while(lecteur->Read()) {
- MessageBox::Show(lecteur["titre"]->ToString()+ " est disponible","titre",MessageBoxButtons::OK,MessageBoxIcon::Information);
- }
- this->BaseDeDonnee->Close();
- }
- };
- }
|
par contre pour ce qui est de insert into, ca pose probleme, je n'ai pas de message d erreur mais rien n'est rajouter dans la base de donnee
Code :
- #pragma once
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- namespace librairie {
- /// <summary>
- /// Description résumée de commande
- ///
- /// AVERTISSEMENT : si vous modifiez le nom de cette classe, vous devrez modifier la
- /// propriété 'Nom du fichier de ressources' de l'outil de compilation de ressource managée
- /// pour tous les fichiers .resx dont dépend cette classe. Dans le cas contraire,
- /// les concepteurs ne pourront pas interagir correctement avec les ressources
- /// localisées associées à ce formulaire.
- /// </summary>
- public ref class commande : public System::Windows::Forms::Form
- {
- public:
- commande(void)
- {this->BaseDonnee = (gcnew System::Data::OleDb::OleDbConnection());
- InitializeComponent();
- //
- //TODO : ajoutez ici le code du constructeur
- //
- }
- protected:
- /// <summary>
- /// Nettoyage des ressources utilisées.
- /// </summary>
- ~commande()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Data::OleDb::OleDbConnection^ BaseDonnee;
- private: System::Data::OleDb::OleDbConnection^ BaseDeDonnee;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Button^ soumettre;
- private: System::Windows::Forms::Button^ effacer;
- private: System::Windows::Forms::Button^ quitter;
- private: System::Windows::Forms::TextBox^ nomtxt;
- private: System::Windows::Forms::TextBox^ prenomtxt;
- private: System::Windows::Forms::TextBox^ adressetxt;
- private: System::Windows::Forms::TextBox^ teltxt;
- private: System::Windows::Forms::TextBox^ titretxt;
- private: System::Windows::Forms::TextBox^ auteurtxt;
- private: System::Windows::Forms::TextBox^ quantitetxt;
- private: System::Windows::Forms::Label^ nom;
- private: System::Windows::Forms::Label^ prenom;
- private: System::Windows::Forms::Label^ adresse;
- private: System::Windows::Forms::Label^ tel;
- private: System::Windows::Forms::Label^ titre;
- private: System::Windows::Forms::Label^ auteur;
- private: System::Windows::Forms::Label^ quantite;
- private: System::ComponentModel::IContainer^ components;
- protected:
- private:
- /// <summary>
- /// Variable nécessaire au concepteur.
- /// </summary>
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
- /// le contenu de cette méthode avec l'éditeur de code.
- /// </summary>
- void InitializeComponent(void)
- {this->BaseDeDonnee = (gcnew System::Data::OleDb::OleDbConnection());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->soumettre = (gcnew System::Windows::Forms::Button());
- this->effacer = (gcnew System::Windows::Forms::Button());
- this->quitter = (gcnew System::Windows::Forms::Button());
- this->nomtxt = (gcnew System::Windows::Forms::TextBox());
- this->prenomtxt = (gcnew System::Windows::Forms::TextBox());
- this->adressetxt = (gcnew System::Windows::Forms::TextBox());
- this->teltxt = (gcnew System::Windows::Forms::TextBox());
- this->titretxt = (gcnew System::Windows::Forms::TextBox());
- this->auteurtxt = (gcnew System::Windows::Forms::TextBox());
- this->quantitetxt = (gcnew System::Windows::Forms::TextBox());
- this->nom = (gcnew System::Windows::Forms::Label());
- this->prenom = (gcnew System::Windows::Forms::Label());
- this->adresse = (gcnew System::Windows::Forms::Label());
- this->tel = (gcnew System::Windows::Forms::Label());
- this->titre = (gcnew System::Windows::Forms::Label());
- this->auteur = (gcnew System::Windows::Forms::Label());
- this->quantite = (gcnew System::Windows::Forms::Label());
- this->SuspendLayout();
- //
- // BaseDeDonnee
- //
- this->BaseDeDonnee->ConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=librairie en ligne.mdb";
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->label1->Location = System::Drawing::Point(258, 38);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(218, 46);
- this->label1->TabIndex = 0;
- this->label1->Text = L"commande";
- //
- // soumettre
- //
- this->soumettre->Location = System::Drawing::Point(64, 587);
- this->soumettre->Name = L"soumettre";
- this->soumettre->Size = System::Drawing::Size(75, 23);
- this->soumettre->TabIndex = 1;
- this->soumettre->Text = L"soumettre";
- this->soumettre->UseVisualStyleBackColor = true;
- this->soumettre->Click += gcnew System::EventHandler(this, &commande::soumettre_Click);
- //
- // effacer
- //
- this->effacer->Location = System::Drawing::Point(362, 587);
- this->effacer->Name = L"effacer";
- this->effacer->Size = System::Drawing::Size(75, 23);
- this->effacer->TabIndex = 2;
- this->effacer->Text = L"effacer";
- this->effacer->UseVisualStyleBackColor = true;
- //
- // quitter
- //
- this->quitter->Location = System::Drawing::Point(629, 587);
- this->quitter->Name = L"quitter";
- this->quitter->Size = System::Drawing::Size(75, 23);
- this->quitter->TabIndex = 3;
- this->quitter->Text = L"quitter";
- this->quitter->UseVisualStyleBackColor = true;
- this->quitter->Click += gcnew System::EventHandler(this, &commande::quitter_Click);
- //
- // nomtxt
- //
- this->nomtxt->Location = System::Drawing::Point(400, 138);
- this->nomtxt->Name = L"nomtxt";
- this->nomtxt->Size = System::Drawing::Size(100, 20);
- this->nomtxt->TabIndex = 4;
- //
- // prenomtxt
- //
- this->prenomtxt->Location = System::Drawing::Point(399, 202);
- this->prenomtxt->Name = L"prenomtxt";
- this->prenomtxt->Size = System::Drawing::Size(100, 20);
- this->prenomtxt->TabIndex = 5;
- //
- // adressetxt
- //
- this->adressetxt->Location = System::Drawing::Point(399, 261);
- this->adressetxt->Name = L"adressetxt";
- this->adressetxt->Size = System::Drawing::Size(100, 20);
- this->adressetxt->TabIndex = 6;
- //
- // teltxt
- //
- this->teltxt->Location = System::Drawing::Point(399, 326);
- this->teltxt->Name = L"teltxt";
- this->teltxt->Size = System::Drawing::Size(100, 20);
- this->teltxt->TabIndex = 7;
- //
- // titretxt
- //
- this->titretxt->Location = System::Drawing::Point(399, 390);
- this->titretxt->Name = L"titretxt";
- this->titretxt->Size = System::Drawing::Size(100, 20);
- this->titretxt->TabIndex = 8;
- //
- // auteurtxt
- //
- this->auteurtxt->Location = System::Drawing::Point(399, 448);
- this->auteurtxt->Name = L"auteurtxt";
- this->auteurtxt->Size = System::Drawing::Size(100, 20);
- this->auteurtxt->TabIndex = 9;
- //
- // quantitetxt
- //
- this->quantitetxt->Location = System::Drawing::Point(399, 501);
- this->quantitetxt->Name = L"quantitetxt";
- this->quantitetxt->Size = System::Drawing::Size(100, 20);
- this->quantitetxt->TabIndex = 10;
- //
- // nom
- //
- this->nom->AutoSize = true;
- this->nom->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(0)));
- this->nom->Location = System::Drawing::Point(88, 138);
- this->nom->Name = L"nom";
- this->nom->Size = System::Drawing::Size(27, 13);
- this->nom->TabIndex = 11;
- this->nom->Text = L"nom";
- //
- // prenom
- //
- this->prenom->AutoSize = true;
- this->prenom->Location = System::Drawing::Point(87, 202);
- this->prenom->Name = L"prenom";
- this->prenom->Size = System::Drawing::Size(42, 13);
- this->prenom->TabIndex = 12;
- this->prenom->Text = L"prenom";
- //
- // adresse
- //
- this->adresse->AutoSize = true;
- this->adresse->Location = System::Drawing::Point(87, 261);
- this->adresse->Name = L"adresse";
- this->adresse->Size = System::Drawing::Size(44, 13);
- this->adresse->TabIndex = 13;
- this->adresse->Text = L"adresse";
- //
- // tel
- //
- this->tel->AutoSize = true;
- this->tel->Location = System::Drawing::Point(87, 326);
- this->tel->Name = L"tel";
- this->tel->Size = System::Drawing::Size(18, 13);
- this->tel->TabIndex = 14;
- this->tel->Text = L"tel";
- //
- // titre
- //
- this->titre->AutoSize = true;
- this->titre->Location = System::Drawing::Point(86, 390);
- this->titre->Name = L"titre";
- this->titre->Size = System::Drawing::Size(24, 13);
- this->titre->TabIndex = 15;
- this->titre->Text = L"titre";
- //
- // auteur
- //
- this->auteur->AutoSize = true;
- this->auteur->Location = System::Drawing::Point(87, 448);
- this->auteur->Name = L"auteur";
- this->auteur->Size = System::Drawing::Size(37, 13);
- this->auteur->TabIndex = 16;
- this->auteur->Text = L"auteur";
- //
- // quantite
- //
- this->quantite->AutoSize = true;
- this->quantite->Location = System::Drawing::Point(87, 501);
- this->quantite->Name = L"quantite";
- this->quantite->Size = System::Drawing::Size(45, 13);
- this->quantite->TabIndex = 17;
- this->quantite->Text = L"quantite";
- //
- // commande
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(760, 644);
- this->Controls->Add(this->quantite);
- this->Controls->Add(this->auteur);
- this->Controls->Add(this->titre);
- this->Controls->Add(this->tel);
- this->Controls->Add(this->adresse);
- this->Controls->Add(this->prenom);
- this->Controls->Add(this->nom);
- this->Controls->Add(this->quantitetxt);
- this->Controls->Add(this->auteurtxt);
- this->Controls->Add(this->titretxt);
- this->Controls->Add(this->teltxt);
- this->Controls->Add(this->adressetxt);
- this->Controls->Add(this->prenomtxt);
- this->Controls->Add(this->nomtxt);
- this->Controls->Add(this->quitter);
- this->Controls->Add(this->effacer);
- this->Controls->Add(this->soumettre);
- this->Controls->Add(this->label1);
- this->Name = L"commande";
- this->Text = L"commande";
- this->Load += gcnew System::EventHandler(this, &commande::commande_Load);
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void commande_Load(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void quitter_Click(System::Object^ sender, System::EventArgs^ e) {
- this->~commande();
- }
- private: System::Void soumettre_Click(System::Object^ sender, System::EventArgs^ e) {
- //ouverture base de donne
- // this->BaseDeDonnee->Open();
- //requete
- System::Data::OleDb::OleDbCommand^ requete = (gcnew System::Data::OleDb::OleDbCommand(" INSERT INTO client(Nom,Prenom) VALUES ('dede','gregory')",this->BaseDeDonnee));
- System::Data::OleDb::OleDbDataReader^ lecteur;
- //lecteur=requete->ExecuteReader();
- this->BaseDeDonnee->Open();
- requete->ExecuteNonQuery();
- MessageBox::Show("texte","titre",MessageBoxButtons::OK,MessageBoxIcon::Information);
- this->BaseDeDonnee->Close();
- }
- };
- }
|
merci d'avance de votre aide |