You are on page 1of 2

Utilisation POO dans ADO

Par une classe en Mode Connecter

Question 1
Creation de la clase CEmploye
class CEmploye
{

public int numero;


public string nom;
public string job;
public int nsuperviseur;
public int ndepartement;
public double salaire;

SqlConnection cn = new SqlConnection(@"Data Source=.\sqlexpress01;Initial


Catalog=Test1;Integrated Security=True");

SqlCommand cmd = new SqlCommand();

SqlDataReader dr;

public CEmploye() {
if (cn.State == ConnectionState.Closed) {
cn.Open();
}

cmd.Connection = cn;

public CEmploye(int ne)


{
this.numero = ne;

if (cn.State == ConnectionState.Closed)
{
cn.Open();
}

cmd.Connection = cn;

1
public CEmploye(int ne,string n,string j, int ns,int nd,double s)
{
this.numero = ne;
this.nom = n;
this.job = j;
this.nsuperviseur = ns;
this.ndepartement = nd;
this.salaire = s;

if (cn.State == ConnectionState.Closed)
{
cn.Open();
}

cmd.Connection = cn;

public int Ajouter() {


cmd.CommandText = "insert into employe values("+ this.numero +",'"+ this.nom +"','"+
this.job +"',"+ this.nsuperviseur +","+ this.ndepartement +","+ this.salaire +")";

return cmd.ExecuteNonQuery();
}

public int Modifier()


{
cmd.CommandText = "update employe set empname='" + this.nom + "',job='" + this.job +
"',supervisor=" + this.nsuperviseur + ",Deptno=" + this.ndepartement + ",salaire=" +
this.salaire + " where Empno =" + this.numero ;
return cmd.ExecuteNonQuery();
}

public int Supprimer()


{
cmd.CommandText = "delete from employe where Empno = " + this.numero ;
return cmd.ExecuteNonQuery();
}

public SqlDataReader Rechercher()


{
SqlDataReader dr;
cmd.CommandText = "select * from employe where Empno = " + this.numero;
dr = cmd.ExecuteReader();
return dr;
}

public DataTable Afficher()


{
DataTable t = new DataTable();
cmd.CommandText = "select * from employe";
dr = cmd.ExecuteReader();
t.Load(dr);
return t;
}
}
2

You might also like