Se connecter avec
S'enregistrer | Connectez-vous

chercher l'erreur sur code C++

Dernière réponse : dans Programmation

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

Autres pages sur : chercher erreur code

Lassé par la pub ? Créez un compte

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;
}

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

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

par curiosité, je voudrais bien savoir ce que t'as pas compris dans:
Citation :

PQresultStatus

Renvoie l'état du résultat d'une commande.

  1. ExecStatusType PQresultStatus(const PGresult *res);


PQresultStatus peut renvoyer une des valeurs suivantes :

PGRES_EMPTY_QUERY

La chaîne envoyée au serveur était vide.
PGRES_COMMAND_OK

Fin avec succès d'une commande ne renvoyant aucune donnée.
PGRES_TUPLES_OK

Fin avec succès d'une commande renvoyant des données (telle que SELECT ou SHOW).

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 dit :
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


ensuite tu présentes un autre code, dont la relation avec celui ci n'est pas du tout claire.

alors est ce que pour
  1. nomtmp = gcnew String(PQgetvalue(res, 0, 0));

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?


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::D ata;
using namespace System::D 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::D rawing::p oint(42, 118);
this->label3->Name = L"label3";
this->label3->Size = System::D rawing::Size(93, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Nom (de la BDD) :";
//
// textBox3
//
this->textBox3->Location = System::D rawing::p oint(141, 115);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::D rawing::Size(106, 20);
this->textBox3->TabIndex = 2;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::D rawing::p oint(58, 77);
this->label2->Name = L"label2";
this->label2->Size = System::D rawing::Size(77, 13);
this->label2->TabIndex = 3;
this->label2->Text = L"Mot de passe :";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::D rawing::p oint(76, 33);
this->label1->Name = L"label1";
this->label1->Size = System::D rawing::Size(59, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Utilisateur :";
//
// textBox1
//
this->textBox1->Location = System::D rawing::p oint(141, 30);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::D 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::D rawing::p oint(36, 20);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::D 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::D rawing::p oint(141, 74);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::D rawing::Size(106, 20);
this->textBox2->TabIndex = 1;
//
// button1
//
this->button1->Location = System::D rawing::p oint(145, 483);
this->button1->Name = L"button1";
this->button1->Size = System::D 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::D rawing::p oint(24, 179);
this->label4->Name = L"label4";
this->label4->Size = System::D rawing::Size(76, 13);
this->label4->TabIndex = 14;
this->label4->Text = L"mot de passe :";
//
// textBox4
//
this->textBox4->Location = System::D rawing::p oint(123, 176);
this->textBox4->MaxLength = 30;
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::D rawing::Size(106, 20);
this->textBox4->TabIndex = 7;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::D rawing::p oint(51, 138);
this->label5->Name = L"label5";
this->label5->Size = System::D rawing::Size(49, 13);
this->label5->TabIndex = 12;
this->label5->Text = L"Prénom :";
//
// textBox5
//
this->textBox5->Location = System::D rawing::p oint(123, 135);
this->textBox5->MaxLength = 30;
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System::D rawing::Size(106, 20);
this->textBox5->TabIndex = 6;
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::D rawing::p oint(65, 94);
this->label6->Name = L"label6";
this->label6->Size = System::D rawing::Size(35, 13);
this->label6->TabIndex = 10;
this->label6->Text = L"Nom :";
//
// textBox6
//
this->textBox6->Location = System::D rawing::p oint(123, 91);
this->textBox6->MaxLength = 20;
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System::D 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::D rawing::p oint(36, 228);
this->groupBox2->Name = L"groupBox2";
this->groupBox2->Size = System::D rawing::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::D rawing::p oint(315, 53);
this->label8->Name = L"label8";
this->label8->Size = System::D rawing::Size(72, 13);
this->label8->TabIndex = 24;
this->label8->Text = L"Adresse mail :";
//
// textBox8
//
this->textBox8->Location = System::D rawing::p oint(410, 50);
this->textBox8->MaxLength = 30;
this->textBox8->Name = L"textBox8";
this->textBox8->Size = System::D rawing::Size(106, 20);
this->textBox8->TabIndex = 8;
//
// label10
//
this->label10->AutoSize = true;
this->label10->Location = System::D rawing::p oint(289, 138);
this->label10->Name = L"label10";
this->label10->Size = System::D rawing::Size(98, 13);
this->label10->TabIndex = 20;
this->label10->Text = L"Mot de passe mail :";
//
// textBox10
//
this->textBox10->Location = System::D rawing::p oint(410, 135);
this->textBox10->MaxLength = 30;
this->textBox10->Name = L"textBox10";
this->textBox10->Size = System::D rawing::Size(106, 20);
this->textBox10->TabIndex = 10;
//
// label11
//
this->label11->AutoSize = true;
this->label11->Location = System::D rawing::p oint(317, 94);
this->label11->Name = L"label11";
this->label11->Size = System::D rawing::Size(70, 13);
this->label11->TabIndex = 18;
this->label11->Text = L"Compte mail :";
//
// textBox11
//
this->textBox11->Location = System::D rawing::p oint(410, 91);
this->textBox11->MaxLength = 30;
this->textBox11->Name = L"textBox11";
this->textBox11->Size = System::D rawing::Size(106, 20);
this->textBox11->TabIndex = 9;
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::D rawing::p oint(61, 53);
this->label7->Name = L"label7";
this->label7->Size = System::D rawing::Size(39, 13);
this->label7->TabIndex = 16;
this->label7->Text = L"Login :";
//
// textBox7
//
this->textBox7->Enabled = false;
this->textBox7->Location = System::D rawing::p oint(123, 50);
this->textBox7->Name = L"textBox7";
this->textBox7->Size = System::D rawing::Size(106, 20);
this->textBox7->TabIndex = 4;
//
// button2
//
this->button2->Location = System::D rawing::p oint(354, 154);
this->button2->Name = L"button2";
this->button2->Size = System::D rawing::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::D rawing::p oint(354, 483);
this->button3->Name = L"button3";
this->button3->Size = System::D rawing::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::D rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::D rawing::SystemColors::GradientInactiveCaption;
this->ClientSize = System::D rawing::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::D rawing::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::o bject^ o,System::EventArgs^ e){
//this->textboxLogin();
}

private: System::Void button1_Click(System::o 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::o 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::o 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::D ata;
using namespace System::D rawing;


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::D rawing::p oint(96, 130);
this->button1->Name = L"button1";
this->button1->Size = System::D rawing::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::D rawing::SystemColors::GradientInactiveCaption;
this->textBox1->Location = System::D rawing::p oint(12, 12);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::D rawing::Size(276, 104);
this->textBox1->TabIndex = 1;
//
// FenAlerte
//
this->AutoScaleDimensions = System::D rawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::D rawing::SystemColors::GradientInactiveCaption;
this->ClientSize = System::D rawing::Size(300, 171);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Icon = (cli::safe_cast<System::D rawing::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::D efinirTexte(String^ texte){
this->textBox1->Text = texte;
}
private: System::Void button1_Click(System::o 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::p 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 dit :
juste la fonction d'où est issue le premier code que tu as posté


la fonction FenPrinc::textboxLogin() aurait suffit!
même juste ca:
  1. if (PQresultStatus(res) != PGRES_TUPLES_OK)
  2. {
  3. fprintf(stderr, "SELECT failed: %s", PQerrorMessage(conn));
  4. PQclear(res);
  5. }
  6. // S'il y a une erreur lors de l'exécution de la requete,
  7. // il poursuit quand même le code!!!
  8. String^ nomtmp;
  9. // et donc la il utilise un "res" qui n'est pas bon
  10. nomtmp = gcnew String(PQgetvalue(res, 0, 0));

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.
Lassé par la pub ? Créez un compte
Tom's guide dans le monde