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
|
private NpgsqlConnection maConnexion = new NpgsqlConnection();
public static NpgsqlConnection myCurcon = new NpgsqlConnection();
//Ouverture
public void ouvreBase()
{
string maChaine = string.Empty;
maChaine = "Server=localhost;Port=5432;User Id=*****;Password=*****;Database=myDb;";
maConnexion.ConnectionString = maChaine;
try{
maConnexion.Open();
myCurcon = maConnexion;
}
catch (Exception monEx)
{
MessageBox.Show("Erreur de connexion:\n" + monEx.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
/*************************/
public void AjoutUtilisateur(string myIdentifiant, string myMdp, string myNom, string myContact, string myNomgroupe)
{
string myPgChaine = "";
//myNom = AjouteCote(myNom);
//myNom = UTF8Encode(myNom);
//myPgChaine = "INSERT INTO utilisateur(identifiant,mdp,nom,contact,nomgroupe,idutilisateur)";
myPgChaine = "INSERT INTO utilisateur";
myPgChaine = myPgChaine + " VALUES('" + AjouteCote(myIdentifiant);
myPgChaine = myPgChaine + "','" + AjouteCote(myMdp) + "','" + myNom;
myPgChaine = myPgChaine + "','" + AjouteCote(myContact) + "','" + AjouteCote(myNomgroupe) + "')";
int LigneAjoute;
NpgsqlCommand AddCmd = new NpgsqlCommand(myPgChaine, myCurcon);
try
{
LigneAjoute = AddCmd.ExecuteNonQuery();
MessageBox.Show(LigneAjoute + " ligne(s) ajoutée(s)");
}
catch (Exception myEx)
{
MessageBox.Show(myEx.Message, "Ajout utilisateur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/***********************************/
public string AjouteCote(string chainePassee)
{
chainePassee = chainePassee.Replace("'", "''");
return chainePassee;
} |
Partager