chercher l'erreur sur code C++
Forum Programmation : chercher l'erreur sur code C++
voila je c'est que j'ai une erreur dans le code qui suit mais je ne c'est pas laquelle!lol
______________________________________________________
String^ nomtmp;
nomtmp = gcnew String(PQgetvalue(res, 0, 0));
this->textBox7->Text = nomtmp;
PQclear(res);
//Ferme la connexion à la base de données et libère la mémoire
PQfinish(conn);
______________________________________________________
Pouvez vous m'aider a trouvé?merçi
ya pa d amateur de c++ la?
Ecris correctement sous peine de te voir fermer le topic.
le message d'erreur peut aider
Message édité par coca25 le 06-06-2007 à 16:51:15
Penser à voir les tutos, ca peut aider!
Répondre à coca25
erf c'est malin d'éditer ! on va croire que je raconte n'importe quoi ...quoi que ...
Message édité par okinou le 13-06-2007 à 01:22:52
ok je le fais plus, c'est que je viens de me rappeler que je l'ai déjà vu quelque part le String (je parle de programmation
)
et après une recherche, c'est du C++/CLI et non du C++
Penser à voir les tutos, ca peut aider!
Répondre à coca25
personne d'autre pourrait m'aider?
voiçi le code qui me permet de me connecté a la base:
#pragma endregion
private:
String^ Informationsconn;
int FenPrinc::numeroLogin(){
String^ connstatus;
String^ requete;
PGconn *conn;
PGresult *res;
String^ tmp="0";
int nbr=0;
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(this->Informationsconn);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
conn = PQconnectdb(chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQstatus(conn) != CONNECTION_OK)
{
connstatus="PROBLEM DE CONNECTION";
}else{
//requete = "select count(*) from utilisateur where nom = '"+nom+"' and prenom = '"+prénom+"'"+" and mot_de_passe = '"+mdp+"'";
requete = "select count(*)+1 from utilisateur";
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(requete);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
res = PQexec(conn, chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
PQclear(res);
tmp="0";
}else{
tmp= gcnew String(PQgetvalue(res, 0, 0));
PQclear(res);
}
/* Ferme la connexion à la base de données et libère la mémoire */
PQfinish(conn);
}
nbr = Convert::ToInt32(tmp);
return nbr;
}
message d'erreur, ca évite d'avoir à comprendre tout le prog
Penser à voir les tutos, ca peut aider!
Répondre à coca25
le message d'eereur est le suivant:
Une exception non gérée du type 'System.AccessViolationException' s'est produite dans AjoutAdministrateur.exe
Informations supplémentaires*: Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée.
et puis j'ai le choix entre continué ou quitter, mais dans les deux cas toute façon il quitte l'application
est ce que tu as vérifié que la requête te retourne bien un résultat avant de faire le PQgetvalue(res, 0, 0) ?
encadre ton code concérné avec un try
puis un catch pour avoir plus de précision sur l'exception levée
Penser à voir les tutos, ca peut aider!
Répondre à coca25
comment vérifié quel me renvoi une valeur.
if (PQresultStatus(res) != PGRES_TUPLES_OK)
c'est bien toi qui a fait le programme ??
Penser à voir les tutos, ca peut aider!
Répondre à coca25
non justement c'est pas moi, je suis en stage la, et mon tuteur me demande de faire marché sa!J'ai fait que 2 mois de C++ pour l'instant, sinon je fait que du C, alors c'est dur pour moi.J'aimerai bien ke tu me décrive tout parce que la je suis largué.merçi
demande à ton tuteur de t'aider ca sera encore mieux, car là...
Message édité par okinou le 07-06-2007 à 11:48:50
Il n'est pas la pendant 1 semaine, alors si j'ai pas avançer je vais me faire mal voir
la tu utilises une api postgres C, donc tu ne dois pas etre déboussolé
http://docs.postgresqlfr.org/8.1/libpq-exec.html
Penser à voir les tutos, ca peut aider!
Répondre à coca25
je c'est bien, ce document je l'ai lu et relu! j'en ressort pas grand chose.
par curiosité, je voudrais bien savoir ce que t'as pas compris dans:
| Citation :
Renvoie l'état du résultat d'une commande.
PQresultStatus peut renvoyer une des valeurs suivantes : PGRES_EMPTY_QUERY La chaîne envoyée au serveur était vide. Fin avec succès d'une commande ne renvoyant aucune donnée. Fin avec succès d'une commande renvoyant des données (telle que SELECT ou SHOW). |
Message édité par coca25 le 07-06-2007 à 12:07:30
Penser à voir les tutos, ca peut aider!
Répondre à coca25
ba pour sa:
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
PQclear(res);
tmp="0";
}else{
tmp= gcnew String(PQgetvalue(res, 0, 0));
PQclear(res);
}
/* Ferme la connexion à la base de données et libère la mémoire */
PQfinish(conn);
}
nbr = Convert::ToInt32(tmp);
return nbr;
}
si PQresultStatus(res) est différent de PGRES_TUPLES_OK, alors après on a sa : fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
PQclear(res);
tmp="0";
sinon on a sa tmp= gcnew String(PQgetvalue(res, 0, 0));
donc la il devrai aller dans le esle.
Dans mon application si je je rentre pas le bon administrateur, ni le bon mot de passe et le bon nom de la basse, il me dit bien que mes identifiants sont incorect.
bon, je récapitule:
tu commences par dire que t'as une erreur dans le code suivant:
| corey35 a écrit : voila je c'est que j'ai une erreur dans le code qui suit mais je ne c'est pas laquelle!lol nomtmp = gcnew String(PQgetvalue(res, 0, 0)); this->textBox7->Text = nomtmp; ______________________________________________________ Pouvez vous m'aider a trouvé?merçi |
ensuite tu présentes un autre code, dont la relation avec celui ci n'est pas du tout claire.
alors est ce que pour
Code :
|
tu as vérifié le resultat (res) de la requete sql que tu donnes en paramètre?
et pour l'exception, est ce que tu as utilisé le try/catch?
Message édité par coca25 le 07-06-2007 à 14:26:43
Penser à voir les tutos, ca peut aider!
Répondre à coca25
oui j'ai vérifié le résultat des (res) est c'est bon. non je n'ai pas utilisé le try/catch, tu peu le m'expliquer vite fait s'il te plaît?merçi
http://c.developpez.com/faq/cpp/?page=exceptions
tu peux poster le code de la fonction dont est issue le code de ton premier message?
Message édité par coca25 le 07-06-2007 à 14:38:51
Penser à voir les tutos, ca peut aider!
Répondre à coca25
tu peu pas me le faire rapidement la?parce que sur developpez sa met trop de temps a répondre, merçi
personne ne veut plus m'aider???
tu n'as pas posté le code
Penser à voir les tutos, ca peut aider!
Répondre à coca25
tu veux quel code?parce que si je met tou yen a pour 5 pages je pense, dit moi la partie qu'il te faut.
juste la fonction d'où est issue le premier code que tu as posté
Penser à voir les tutos, ca peut aider!
Répondre à coca25
je te met tou comme sa c'est bon:
stdafx.h:
#pragma comment (lib, "libpq.lib" )
#pragma once
#include <windows.h>
#include "libpq-fe.h"
#include "string.h"
FenPrinc.h:
#pragma once
#include "FenAlerte.h"
namespace AjoutAdministrateur {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:
ata;
using namespace System:
rawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class FenPrinc : public System::Windows::Forms::Form
{
public:
FenPrinc(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~FenPrinc()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label3;
protected:
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::TextBox^ textBox6;
private: System::Windows::Forms::GroupBox^ groupBox2;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::TextBox^ textBox8;
private: System::Windows::Forms::Label^ label10;
private: System::Windows::Forms::TextBox^ textBox10;
private: System::Windows::Forms::Label^ label11;
private: System::Windows::Forms::TextBox^ textBox11;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::TextBox^ textBox7;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(FenPrinc::typeid));
this->label3 = (gcnew System::Windows::Forms::Label());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->label4 = (gcnew System::Windows::Forms::Label());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->label5 = (gcnew System::Windows::Forms::Label());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->label6 = (gcnew System::Windows::Forms::Label());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
this->label8 = (gcnew System::Windows::Forms::Label());
this->textBox8 = (gcnew System::Windows::Forms::TextBox());
this->label10 = (gcnew System::Windows::Forms::Label());
this->textBox10 = (gcnew System::Windows::Forms::TextBox());
this->label11 = (gcnew System::Windows::Forms::Label());
this->textBox11 = (gcnew System::Windows::Forms::TextBox());
this->label7 = (gcnew System::Windows::Forms::Label());
this->textBox7 = (gcnew System::Windows::Forms::TextBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->groupBox1->SuspendLayout();
this->groupBox2->SuspendLayout();
this->SuspendLayout();
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System:
rawing:
oint(42, 118);
this->label3->Name = L"label3";
this->label3->Size = System:
rawing::Size(93, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Nom (de la BDD) :";
//
// textBox3
//
this->textBox3->Location = System:
rawing:
oint(141, 115);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System:
rawing::Size(106, 20);
this->textBox3->TabIndex = 2;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System:
rawing:
oint(58, 77);
this->label2->Name = L"label2";
this->label2->Size = System:
rawing::Size(77, 13);
this->label2->TabIndex = 3;
this->label2->Text = L"Mot de passe :";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System:
rawing:
oint(76, 33);
this->label1->Name = L"label1";
this->label1->Size = System:
rawing::Size(59, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Utilisateur :";
//
// textBox1
//
this->textBox1->Location = System:
rawing:
oint(141, 30);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System:
rawing::Size(106, 20);
this->textBox1->TabIndex = 0;
//
// groupBox1
//
this->groupBox1->Controls->Add(this->label3);
this->groupBox1->Controls->Add(this->textBox3);
this->groupBox1->Controls->Add(this->label2);
this->groupBox1->Controls->Add(this->textBox2);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Controls->Add(this->textBox1);
this->groupBox1->Location = System:
rawing:
oint(36, 20);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System:
rawing::Size(294, 165);
this->groupBox1->TabIndex = 7;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Base de données";
//
// textBox2
//
this->textBox2->Location = System:
rawing:
oint(141, 74);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System:
rawing::Size(106, 20);
this->textBox2->TabIndex = 1;
//
// button1
//
this->button1->Location = System:
rawing:
oint(145, 483);
this->button1->Name = L"button1";
this->button1->Size = System:
rawing::Size(120, 31);
this->button1->TabIndex = 11;
this->button1->Text = L"Ajouter administrateur";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &FenPrinc::button1_Click);
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System:
rawing:
oint(24, 179);
this->label4->Name = L"label4";
this->label4->Size = System:
rawing::Size(76, 13);
this->label4->TabIndex = 14;
this->label4->Text = L"mot de passe :";
//
// textBox4
//
this->textBox4->Location = System:
rawing:
oint(123, 176);
this->textBox4->MaxLength = 30;
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System:
rawing::Size(106, 20);
this->textBox4->TabIndex = 7;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System:
rawing:
oint(51, 138);
this->label5->Name = L"label5";
this->label5->Size = System:
rawing::Size(49, 13);
this->label5->TabIndex = 12;
this->label5->Text = L"Prénom :";
//
// textBox5
//
this->textBox5->Location = System:
rawing:
oint(123, 135);
this->textBox5->MaxLength = 30;
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System:
rawing::Size(106, 20);
this->textBox5->TabIndex = 6;
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System:
rawing:
oint(65, 94);
this->label6->Name = L"label6";
this->label6->Size = System:
rawing::Size(35, 13);
this->label6->TabIndex = 10;
this->label6->Text = L"Nom :";
//
// textBox6
//
this->textBox6->Location = System:
rawing:
oint(123, 91);
this->textBox6->MaxLength = 20;
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System:
rawing::Size(106, 20);
this->textBox6->TabIndex = 5;
//
// groupBox2
//
this->groupBox2->Controls->Add(this->label8);
this->groupBox2->Controls->Add(this->textBox8);
this->groupBox2->Controls->Add(this->label10);
this->groupBox2->Controls->Add(this->textBox10);
this->groupBox2->Controls->Add(this->label11);
this->groupBox2->Controls->Add(this->textBox11);
this->groupBox2->Controls->Add(this->label7);
this->groupBox2->Controls->Add(this->textBox7);
this->groupBox2->Controls->Add(this->label4);
this->groupBox2->Controls->Add(this->textBox4);
this->groupBox2->Controls->Add(this->label5);
this->groupBox2->Controls->Add(this->textBox5);
this->groupBox2->Controls->Add(this->label6);
this->groupBox2->Controls->Add(this->textBox6);
this->groupBox2->Enabled = false;
this->groupBox2->Location = System::Drawing:
oint(36, 228);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::Drawing::Size(537, 228);
this->groupBox2->TabIndex = 15;
this->groupBox2->TabStop = false;
this->groupBox2->Text = L"Informations administrateur";
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing:
oint(315, 53);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(72, 13);
this->label8->TabIndex = 24;
this->label8->Text = L"Adresse mail :";
//
// textBox8
//
this->textBox8->Location = System::Drawing:
oint(410, 50);
this->textBox8->MaxLength = 30;
this->textBox8->Name = L"textBox8";
this->textBox8->Size = System::Drawing::Size(106, 20);
this->textBox8->TabIndex = 8;
//
// label10
//
this->label10->AutoSize = true;
this->label10->Location = System::Drawing:
oint(289, 138);
this->label10->Name = L"label10";
this->label10->Size = System::Drawing::Size(98, 13);
this->label10->TabIndex = 20;
this->label10->Text = L"Mot de passe mail :";
//
// textBox10
//
this->textBox10->Location = System::Drawing:
oint(410, 135);
this->textBox10->MaxLength = 30;
this->textBox10->Name = L"textBox10";
this->textBox10->Size = System::Drawing::Size(106, 20);
this->textBox10->TabIndex = 10;
//
// label11
//
this->label11->AutoSize = true;
this->label11->Location = System::Drawing:
oint(317, 94);
this->label11->Name = L"label11";
this->label11->Size = System::Drawing::Size(70, 13);
this->label11->TabIndex = 18;
this->label11->Text = L"Compte mail :";
//
// textBox11
//
this->textBox11->Location = System::Drawing:
oint(410, 91);
this->textBox11->MaxLength = 30;
this->textBox11->Name = L"textBox11";
this->textBox11->Size = System::Drawing::Size(106, 20);
this->textBox11->TabIndex = 9;
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing:
oint(61, 53);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(39, 13);
this->label7->TabIndex = 16;
this->label7->Text = L"Login :";
//
// textBox7
//
this->textBox7->Enabled = false;
this->textBox7->Location = System::Drawing:
oint(123, 50);
this->textBox7->Name = L"textBox7";
this->textBox7->Size = System::Drawing::Size(106, 20);
this->textBox7->TabIndex = 4;
//
// button2
//
this->button2->Location = System::Drawing:
oint(354, 154);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(120, 31);
this->button2->TabIndex = 3;
this->button2->Text = L"Connecter";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &FenPrinc::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing:
oint(354, 483);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(120, 31);
this->button3->TabIndex = 16;
this->button3->Text = L"Annuler";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &FenPrinc::button3_Click);
//
// FenPrinc
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::GradientInactiveCaption;
this->ClientSize = System::Drawing::Size(625, 549);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->groupBox2);
this->Controls->Add(this->button1);
this->Controls->Add(this->groupBox1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon" )));
this->Name = L"FenPrinc";
this->Text = L"Ajout d\'un administrateur à ADIMED";
this->Load += gcnew System::EventHandler(this, &FenPrinc::FenPrinc_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->groupBox2->ResumeLayout(false);
this->groupBox2->PerformLayout();
this->ResumeLayout(false);
}
#pragma endregion
private:
String^ Informationsconn;
int FenPrinc::numeroLogin(){
String^ connstatus;
String^ requete;
PGconn *conn;
PGresult *res;
String^ tmp="0";
int nbr=0;
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(this->Informationsconn);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
conn = PQconnectdb(chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQstatus(conn) != CONNECTION_OK)
{
connstatus="PROBLEM DE CONNECTION";
}else{
//requete = "select count(*) from utilisateur where nom = '"+nom+"' and prenom = '"+prénom+"'"+" and mot_de_passe = '"+mdp+"'";
requete = "select count(*)+1 from utilisateur";
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(requete);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
res = PQexec(conn, chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
PQclear(res);
tmp="0";
}else{
tmp= gcnew String(PQgetvalue(res, 0, 0));
PQclear(res);
}
/* Ferme la connexion à la base de données et libère la mémoire */
PQfinish(conn);
}
nbr = Convert::ToInt32(tmp);
return nbr;
}
void FenPrinc::AjoutUtil(String^ nom, String^ prenom, String^ mdp, bool secretaire, bool administrateur, String^ email, String^ comptemail, String^ mdpmail, String^ repertoirereception){
String^ connstatus;
String^ requete;
PGconn *conn;
PGresult *res;
String^ tmp="0";
bool executer = false;
int login = numeroLogin();
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(this->Informationsconn);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
conn = PQconnectdb(chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQstatus(conn) != CONNECTION_OK)
{
connstatus="PROBLEM DE CONNECTION";
}else{
requete = "insert into utilisateur values ("+login+",'"+nom+"', '"+prenom+"', '"+mdp+"', false, true, '"+email+"', '"+comptemail+"', '"+mdpmail+"', '"+repertoirereception+"')";
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(requete);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
res = PQexec(conn, chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQresultStatus(res) == PGRES_COMMAND_OK ){
executer=true;
gcnew FenAlerte("Administrateur login : "+login+" AJOUTE" );
}
PQclear(res);
/* Ferme la connexion à la base de données et libère la mémoire */
PQfinish(conn);
}
}
void FenPrinc::textboxLogin(){
String^ connstatus;
PGconn *conn;
PGresult *res;
char* entree = "select count(*)+1 from utilisateur";
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(this->Informationsconn);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
conn = PQconnectdb(chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQstatus(conn) != CONNECTION_OK)
{
connstatus="PROBLEM DE CONNECTION";
}else{
res = PQexec(conn, entree);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
PQclear(res);
}
String^ nomtmp;
nomtmp = gcnew String(PQgetvalue(res, 0, 0));
this->textBox7->Text = nomtmp;
PQclear(res);
//Ferme la connexion à la base de données et libère la mémoire
PQfinish(conn);
}
}
void FenPrinc::FenPrinc_Load(System:
bject^ o,System::EventArgs^ e){
//this->textboxLogin();
}
private: System::Void button1_Click(System:
bject^ sender, System::EventArgs^ e) {
String^ nom = this->textBox6->Text->ToString();
String^ prenom = this->textBox5->Text->ToString();
String^ mdp = this->textBox4->Text->ToString();
String^ email = this->textBox8->Text->ToString();
String^ comptemail = this->textBox11->Text->ToString();
String^ mdpmail = this->textBox10->Text->ToString();
//this->AjoutUtil(this->textBox6->Text->ToString(), this->textBox5->Text->toString(), this->textBox4->Text->toString(),true,true, this->textBox8->Text->toString(), this->textBox11>Text->toString(), this->textBox10->Text->toString());
this->AjoutUtil(nom,prenom,mdp,true,true,email,comptemail,mdpmail,"repertoiredereception" );
}
bool FenPrinc::connectionALaBase(String^ user,String^ mdp,String^ dbname){
PGconn *conn;
bool retour=false;
String^ informationsConnexion;
informationsConnexion = "user = "+user+ " password = "+mdp+" dbname = "+dbname;
IntPtr p = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(informationsConnexion);
LPCSTR chaineChar = reinterpret_cast<LPCSTR>(static_cast<void *>(p));
conn = PQconnectdb(chaineChar);
System::Runtime::InteropServices::Marshal::FreeHGlobal(p);
if (PQstatus(conn) != CONNECTION_OK)
{
gcnew FenAlerte("Identifiants de connexion à la base de données incorrects" );
}else{
this->Informationsconn="user = "+user+ " password = "+mdp+" dbname = "+dbname;
PQfinish(conn);
retour=true;
}
return retour;
}
private: System::Void button2_Click(System:
bject^ sender, System::EventArgs^ e) {
if(this->connectionALaBase(this->textBox1->Text->ToString(),this->textBox2->Text->ToString(),this->textBox3->Text->ToString())){
this->groupBox2->Enabled = true;
this->textboxLogin();
}else{
this->groupBox2->Enabled = false;
}
}
private: System::Void button3_Click(System:
bject^ sender, System::EventArgs^ e) {
this->Close();
}
};
}
FenAlerte.h:
#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 AjoutAdministrateur {
/// <summary>
/// Summary for FenAlerte
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class FenAlerte : public System::Windows::Forms::Form
{
public:
FenAlerte(String^ texte)
{
InitializeComponent();
DefinirTexte(texte);
this->ShowDialog();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~FenAlerte()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(FenAlerte::typeid));
this->button1 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing:
oint(96, 130);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(107, 29);
this->button1->TabIndex = 0;
this->button1->Text = L"OK";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &FenAlerte::button1_Click);
//
// textBox1
//
this->textBox1->BackColor = System::Drawing::SystemColors::GradientInactiveCaption;
this->textBox1->Location = System::Drawing:
oint(12, 12);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(276, 104);
this->textBox1->TabIndex = 1;
//
// FenAlerte
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::GradientInactiveCaption;
this->ClientSize = System::Drawing::Size(300, 171);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon" )));
this->Name = L"FenAlerte";
this->Text = L"Attention";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
///Méthodes personnelles: ======================================================
private:
void FenAlerte::DefinirTexte(String^ texte){
this->textBox1->Text = texte;
}
private: System::Void button1_Click(System:
bject^ sender, System::EventArgs^ e) {
this->Close();
}
};
}
AjoutAdministrateur.cpp:
// AjoutAdministrateur.cpp : main project file.
#include "stdafx.h"
#include "FenPrinc.h"
#include "FenAlerte.h"
using namespace AjoutAdministrateur;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew FenPrinc());
return 0;
}
AssemblyInfo.cpp:
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security:
ermissions;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute("AjoutAdministrateur" )];
[assembly:AssemblyDescriptionAttribute("" )];
[assembly:AssemblyConfigurationAttribute("" )];
[assembly:AssemblyCompanyAttribute("Adicor" )];
[assembly:AssemblyProductAttribute("AjoutAdministrateur" )];
[assembly:AssemblyCopyrightAttribute("Copyright (c) Adicor 2006" )];
[assembly:AssemblyTrademarkAttribute("" )];
[assembly:AssemblyCultureAttribute("" )];
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly:AssemblyVersionAttribute("1.0.*" )];
[assembly:ComVisible(false)];
[assembly:CLSCompliantAttribute(true)];
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
FenAlerte.cpp:
#include "StdAfx.h"
#include "FenAlerte.h"
stdafx.cpp:
#include "stdafx.h"
____________________________________________________________
Voila tout mon code
qu'est ce que t'as pas compris dans:
| coca25 a écrit : juste la fonction d'où est issue le premier code que tu as posté |
la fonction FenPrinc::textboxLogin() aurait suffit!
même juste ca:
Code :
|
Message édité par coca25 le 08-06-2007 à 12:05:23
Penser à voir les tutos, ca peut aider!
Répondre à coca25
et oui, qu'est ce que je fait avec sa?
eh franchement si tu veux que quelqu'un te fasse ton boulot, dis le clairement et attends (ca sera pas moi)
maintenant si tu comprends pas un simple "if", c'est pas gagné...
Penser à voir les tutos, ca peut aider!
Répondre à coca25
bas si un if je comprend! Je fais du C quand même, mais la je ne vois pas du tout dans quelle direction faut aller, c'est pour sa
on ne doit pas risquer d'utiliser une variable non initialisé, en l'occurence, dans ton programme, tu peux avoir:
PQclear(res);
puis
nomtmp = gcnew String(PQgetvalue(res, 0, 0));
ce qui est illogique.
Penser à voir les tutos, ca peut aider!
Répondre à coca25
ce qui veut dire que je libère le stockage de PGresult , puis après je le réutilise pour PQgetvalues, c'est bien sa?
Il y a 2629 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici.

okinou