IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++/CLI Discussion :

Probl�me pour ins�rer une String dans un champ de texte


Sujet :

C++/CLI

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Lyc�en
    Inscrit en
    Juillet 2010
    Messages
    2
    D�tails du profil
    Informations personnelles :
    �ge : 32
    Localisation : France, Paris (�le de France)

    Informations professionnelles :
    Activit� : Lyc�en

    Informations forums :
    Inscription : Juillet 2010
    Messages : 2
    Par d�faut Probl�me pour ins�rer une String dans un champ de texte
    Bonjour/Bonsoir � tous et � toutes,
    je souhaiterais de l'aide afin de cr�er un programme en C++, j'ai commenc� sa cr�ation gr�ce au compilateur Visual C++ Express 2010 (Windows Form), le but de ce programme est de cr�er une requ�te SQL � partir d'informations que l'utilisateur met dans deux champs de texte ( richTextBox2 et TextBox1 ) et la requ�te SQL doit s'afficher dans un autre champ de texte : richTextBox1.

    Form1.h
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
     
    #pragma once
    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
     
    namespace SQL_Gossip {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace std;
     
    	/// <summary>
    	/// Description résumée de Form1
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: ajoutez ici le code du constructeur
    			//
    		}
     
    	protected:
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::RichTextBox^  richTextBox1;
    	protected: 
    	private: System::Windows::Forms::RichTextBox^  richTextBox2;
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::Button^  button2;
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::Label^  label2;
    	private: System::Windows::Forms::LinkLabel^  linkLabel1;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::Label^  label3;
     
     
    	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->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
    			this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->label2 = (gcnew System::Windows::Forms::Label());
    			this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->label3 = (gcnew System::Windows::Forms::Label());
    			this->SuspendLayout();
    			// 
    			// richTextBox1
    			// 
    			this->richTextBox1->Location = System::Drawing::Point(42, 244);
    			this->richTextBox1->Name = L"richTextBox1";
    			this->richTextBox1->Size = System::Drawing::Size(531, 294);
    			this->richTextBox1->TabIndex = 0;
    			this->richTextBox1->Text = L""; //Pas touche
    			// 
    			// richTextBox2
    			// 
    			this->richTextBox2->Location = System::Drawing::Point(42, 70);
    			this->richTextBox2->Name = L"richTextBox2";
    			this->richTextBox2->Size = System::Drawing::Size(531, 96);
    			this->richTextBox2->TabIndex = 1;
    			this->richTextBox2->Text = L"";
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(440, 172);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(133, 23);
    			this->button1->TabIndex = 2;
    			this->button1->Text = L"Créer la requête SQL.";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// button2
    			// 
    			this->button2->Location = System::Drawing::Point(440, 544);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(133, 23);
    			this->button2->TabIndex = 3;
    			this->button2->Text = L"Copier la requête.";
    			this->button2->UseVisualStyleBackColor = true;
    			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Location = System::Drawing::Point(12, 11);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(89, 13);
    			this->label1->TabIndex = 4;
    			this->label1->Text = L"ID de la créature.";
    			// 
    			// label2
    			// 
    			this->label2->AutoSize = true;
    			this->label2->Location = System::Drawing::Point(12, 228);
    			this->label2->Name = L"label2";
    			this->label2->Size = System::Drawing::Size(75, 13);
    			this->label2->TabIndex = 5;
    			this->label2->Text = L"Requête SQL.";
    			// 
    			// linkLabel1
    			// 
    			this->linkLabel1->AutoSize = true;
    			this->linkLabel1->Location = System::Drawing::Point(437, 9);
    			this->linkLabel1->Name = L"linkLabel1";
    			this->linkLabel1->Size = System::Drawing::Size(157, 13);
    			this->linkLabel1->TabIndex = 6;
    			this->linkLabel1->TabStop = true;
    			this->linkLabel1->Text = L"Créer pour le serveur : Achéron.";
    			this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &Form1::linkLabel1_LinkClicked);
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(12, 27);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(100, 20);
    			this->textBox1->TabIndex = 7;
    			this->textBox1->Text = L"";
    			// 
    			// label3
    			// 
    			this->label3->AutoSize = true;
    			this->label3->Location = System::Drawing::Point(15, 54);
    			this->label3->Name = L"label3";
    			this->label3->Size = System::Drawing::Size(84, 13);
    			this->label3->TabIndex = 8;
    			this->label3->Text = L"Texte à afficher.";
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(609, 582);
    			this->Controls->Add(this->label3);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->linkLabel1);
    			this->Controls->Add(this->label2);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->richTextBox2);
    			this->Controls->Add(this->richTextBox1);
    			this->Name = L"Form1";
    			this->Text = L"SQL Créer un gossip.";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    			this->PerformLayout();
     
    		}
    #pragma endregion
     
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
    		 {
    			 //
    		 }
    private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) 
    		 {
    			 //
    		 }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    		 {
    			richTextBox1->Text = ("UPDATE 'creature_template' SET 'npc_flags'=1 WHERE 'entry'='%s'", textBox1->Text);
    		 }
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
    		 {
    		 }
    };
    }

    Mais lorsque j'entre une valeur dans le champ de texte (textBox1), il s'affiche dans le champs de texte final (richTextBox) :
    "la_valeur_entr�e_dans_le_champ_de_texte"
    au lieu de
    "UPDATE 'creature_template' SET 'npc_flags'=1 WHERE 'entry'='la_valeur_entr�e_dans_le_champ_de_texte'"
    Donc si j'entre dans mon champ de texte la valeur "64" le champ de texte1 affiche :
    "64"
    au lieu de
    "UPDATE 'creature_template' SET 'npc_flags'=1 WHERE 'entry'='64' "

  2. #2
    r0d
    r0d est d�connect�
    Membre exp�riment�

    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    Ao�t 2004
    Messages
    4 299
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rh�ne Alpes)

    Informations professionnelles :
    Activit� : D�veloppeur informatique

    Informations forums :
    Inscription : Ao�t 2004
    Messages : 4 299
    Billets dans le blog
    2
    Par d�faut
    Bonjour,

    Ceci n'est pas du c++ � proprement parler. C'est du c++/cli me semble-t-il.
    Il y a un forum d�di� en remontant dans la partie visual c++ du forum; m'est avis que vous obtiendrez plus de r�ponses, et de meilleure qualit�, si vous posez votre question l�-bas.

  3. #3
    Expert confirm�
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    F�vrier 2005
    Messages
    5 505
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 53
    Localisation : France, Val de Marne (�le de France)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 5 505
    Par d�faut
    r0d, c'est peut-�tre du C++/CLI mais le probl�me n'a rien � voir avec .NET.

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    richTextBox1->Text = ("UPDATE 'creature_template' SET 'npc_flags'=1 WHERE 'entry'='%s'", textBox1->Text);
    en C++, la virgule permet de grouper les actions :
    http://msdn.microsoft.com/en-us/libr...xh(VS.80).aspx

    Donc le comportement est normal.
    Ne manque-t-il pas un nom de fonction ou de m�thode devant la parenth�se ouvrant ?

    Regardez du cot� de string.Format (pas de %s � la C, mais du {0} � la .NET).
    http://msdn.microsoft.com/en-us/library/fht0f5be.aspx

  4. #4
    Futur Membre du Club
    Profil pro
    Lyc�en
    Inscrit en
    Juillet 2010
    Messages
    2
    D�tails du profil
    Informations personnelles :
    �ge : 32
    Localisation : France, Paris (�le de France)

    Informations professionnelles :
    Activit� : Lyc�en

    Informations forums :
    Inscription : Juillet 2010
    Messages : 2
    Par d�faut
    Merci merci de votre r�ponse rapide. J'ai r�solu le probl�me en rempla�ant l'ancienne instruction par :

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
     
                            String^ entry 	  = textBox1->Text;
    			String^ gossip_id = textBox2->Text;
    			String^ texte	  = richTextBox2->Text;
     
    			String^ requete = String::Format("UPDATE `creature_template` SET `gossip_menu_id`='{1}', `npcflag`='1' WHERE `entry`='{0}'; \nREPLACE INTO `gossip_menu` (`entry`, `text_id`, `cond_1`, `cond_1_val_1`, `cond_1_val_2`, `cond_2`, `cond_2_val_1`, `cond_2_val_2`) values('{1}','{1}','0','0','0','0','0','0'); \nREPLACE INTO `npc_text` (`ID`, `text0_0`, `text0_1`, `lang0`, `prob0`, `em0_0`, `em0_1`, `em0_2`, `em0_3`, `em0_4`, `em0_5`, `text1_0`, `text1_1`, `lang1`, `prob1`, `em1_0`, `em1_1`, `em1_2`, `em1_3`, `em1_4`, `em1_5`, `text2_0`, `text2_1`, `lang2`, `prob2`, `em2_0`, `em2_1`, `em2_2`, `em2_3`, `em2_4`, `em2_5`, `text3_0`, `text3_1`, `lang3`, `prob3`, `em3_0`, `em3_1`, `em3_2`, `em3_3`, `em3_4`, `em3_5`, `text4_0`, `text4_1`, `lang4`, `prob4`, `em4_0`, `em4_1`, `em4_2`, `em4_3`, `em4_4`, `em4_5`, `text5_0`, `text5_1`, `lang5`, `prob5`, `em5_0`, `em5_1`, `em5_2`, `em5_3`, `em5_4`, `em5_5`, `text6_0`, `text6_1`, `lang6`, `prob6`, `em6_0`, `em6_1`, `em6_2`, `em6_3`, `em6_4`, `em6_5`, `text7_0`, `text7_1`, `lang7`, `prob7`, `em7_0`, `em7_1`, `em7_2`, `em7_3`, `em7_4`, `em7_5`, `WDBVerified`) values('{1}','{2}','{2}','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','','','0','0','0','0','0','0','0','0','1');", gossip_id, entry, texte);
     
    			richTextBox1->Text = requete;
    Merci encore � bient�t.

  5. #5
    Expert confirm�
    Homme Profil pro
    D�veloppeur informatique
    Inscrit en
    F�vrier 2005
    Messages
    5 505
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 53
    Localisation : France, Val de Marne (�le de France)

    Informations professionnelles :
    Activit� : D�veloppeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : F�vrier 2005
    Messages : 5 505
    Par d�faut
    Attention.

    Cha�ne beaucoup trop longue pour �tre maintenable.
    Trop d'actions faites d'une traite sans v�rification des codes retour.
    Manipulation de cha�ne de caract�res susceptibles de faire n'importe quoi en base voir attaque par "SQL injection" car il n'y a aucun contr�le sur les cha�nes.

    N'utiliserez pas la synth�se de requ�te par concat�nation de cha�ne mais utilisez des requ�tes param�tr�es.
    S�parez les diff�rentes �tapes dans des m�thodes distinctes pour pouvoir avoir une bonne analyse des anomalies en cas de probl�me et pour traiter correctement le rollback ou les compensations.

    Utilisez des constants strings � la place de cha�nes explicites dans le code.
    Ce genre de cha�nes et se qui varie le plus durant le d�veloppement de l'application et de la base de donn�es.

    En s�parent les requ�tes par des m�thodes distinctes et en utilisant des constantes vous aurez une application qui pourra plus facilement �tre converti en application multi-tier.

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. [XL-2007] Probl�me pour ins�rer une ligne avant champ fusionn�
    Par Tempas dans le forum Macros et VBA Excel
    R�ponses: 3
    Dernier message: 28/04/2010, 14h22
  2. [VBA-E] Probl�me pour ins�rer des lignes dans une feuille Excel
    Par skystef dans le forum Macros et VBA Excel
    R�ponses: 2
    Dernier message: 16/04/2007, 14h13
  3. Comment fait-on pour ins�rer une date dans un champs DateTime
    Par gibea00 dans le forum Acc�s aux donn�es
    R�ponses: 1
    Dernier message: 14/01/2007, 01h04
  4. Probl�me pour ins�rer une variable dans un champs
    Par BOUTRAIS dans le forum Access
    R�ponses: 2
    Dernier message: 11/04/2006, 22h45
  5. R�ponses: 4
    Dernier message: 09/02/2006, 15h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo