abdelwaheb ammar

abdelwaheb ammar

  • 1.3k
  • 457
  • 124.6k

foreach statement cannot operate on variables of type

Dec 21 2015 10:05 AM

hello i try to create an object named 'gerant'

 class gerant { 
public double CIN_GERANT, NUM_TEL_GERANT, MOBILE_GERANT; 
public string NOM_GERANT, PRENOM_GERANT, ADRESSE__GERANT, MAIL_GERANT, VILLE_GERANT; 
public int CP_GERANT; public DateTime DATE_GERANT; 
public gerant(double _Cin_gerant, string _Nom_Gerant, string _Prenom_Gerant, string _Adresse_Gerant, double _Num_Tel_Gerant, string _Mail_Gerant, double _Mobile_Gerant, int _cp_gerant, string _ville_gerant, DateTime _date_gerant) 
{ this.CIN_GERANT = _Cin_gerant;
 this.NOM_GERANT = _Nom_Gerant; 
this.PRENOM_GERANT = _Prenom_Gerant; 
this.ADRESSE__GERANT = _Adresse_Gerant;
 this.NUM_TEL_GERANT = _Num_Tel_Gerant; 
this.MAIL_GERANT = _Mail_Gerant;
 this.MOBILE_GERANT = _Mobile_Gerant; 
this.CP_GERANT = _cp_gerant; 
this.VILLE_GERANT = _ville_gerant;
 this.DATE_GERANT = _date_gerant; 
} 
public gerant getinfogerant()
 {         
gerant gerer = null; 
string sql_gerant = "select CIN,NOM,PRENOM,ADRESS_PERSONNEL,NUM_TEL,MAIL,MOBILE,CP_GERANT,VILLE_GERANT,DATE_CIN from GERANT"; 
        connexion connect = new connexion(); 
OleDbConnection connection = connect.getconnexion(); 
// try //{        
 connection.Open(); 
OleDbCommand cmd = new OleDbCommand(sql_gerant, connection); 
OleDbDataReader reader = cmd.ExecuteReader(); 
if (reader.Read()) {             
gerer = new gerant(reader.GetDouble(0), 
                reader.GetString(1),    
             reader.GetString(2),         
        reader.GetString(3),        
     reader.GetDouble(4),        
         reader.GetString(5),        
         reader.GetDouble(6),         
        reader.GetInt32(7),         
        reader.GetString(8),    
             reader.GetDateTime(9) )
; 
}        
 connection.Close(); 
return gerer; } }

but when i try to fill my combobox with gerant i try to insert this code

 foreach(Modele.gerant ligne in liste_gerant) { }

but i make this error for me foreach statement cannot operate on variables of type 'gerant' because 'gerant' does not contain a public definition for 'GetEnumerator'

how can i resolve that?


Answers (3)