Retourner tableau csharp
houba80
Messages postés
63
Statut
Membre
-
houba80 Messages postés 63 Statut Membre -
houba80 Messages postés 63 Statut Membre -
Slaut cher mombre je suis entrain de developper un GED avec C#, j'ai une classe Groupe qui contient la méthode id_groupe(), cette derniere va me renvoyer les ID des groupe dans un tableau dynamique afin que je puisse affecter un utilisateur lors de sa création a un groupe, mais j'arrive pas a le faire, voici le code de ma méthode :
public List<string> id_groupe()
{
string rsql;
List<string> id = new List<string>();
rsql = "select * from groupe";
try
{
SqlCommand myCommand = new SqlCommand(rsql, CnxBase.myConn);
myCommand.Transaction = CnxBase.trans;
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
for (int i = 0; i < id.Capacity ; i++)
{
id.Insert(i, (String)myReader["ID_groupe"]) ;
// id[i] = "iheb";
}
}
myReader.Close();
return id;
}
catch (Exception myErr)
{
throw (new Exception(myErr.ToString()));
}
}
et voici son appel dans la classe AjouterUtilisateur:
List<string> id_grp= new List<string>;
for (int i = 0; i < id_grp.Capacity; i++)
{
id_grp[i] = (string)(myGroupe.id_groupe().ToString());
groupe.Items.Add(id_grp[i]); //ceci est un combobox
}
Merci pour vous j'ai besoin de votre aide
public List<string> id_groupe()
{
string rsql;
List<string> id = new List<string>();
rsql = "select * from groupe";
try
{
SqlCommand myCommand = new SqlCommand(rsql, CnxBase.myConn);
myCommand.Transaction = CnxBase.trans;
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
for (int i = 0; i < id.Capacity ; i++)
{
id.Insert(i, (String)myReader["ID_groupe"]) ;
// id[i] = "iheb";
}
}
myReader.Close();
return id;
}
catch (Exception myErr)
{
throw (new Exception(myErr.ToString()));
}
}
et voici son appel dans la classe AjouterUtilisateur:
List<string> id_grp= new List<string>;
for (int i = 0; i < id_grp.Capacity; i++)
{
id_grp[i] = (string)(myGroupe.id_groupe().ToString());
groupe.Items.Add(id_grp[i]); //ceci est un combobox
}
Merci pour vous j'ai besoin de votre aide
A voir également:
- Retourner tableau csharp
- Tableau word - Guide
- Retourner ecran pc - Guide
- Tableau ascii - Guide
- Retourner une vidéo - Guide
- Trier un tableau excel - Guide
1 réponse
public List<string> GetIdGroupe()
{
string rsql = "SELECT * FROM groupe";
List<string> liste_id = new List<string>();
try
{
SqlCommand myCommand = new SqlCommand(rsql, CnxBase.myConn);
myCommand.Transaction = CnxBase.trans;
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
liste_id.Add((string)myReader["ID_Groupe"]);
}
myReader.Close();
return liste_id;
}
catch (Exception myErr)
{
throw (new Exception(myErr.ToString()));
}
}
//appel
List<string> liste_id = new List<string>();
liste_id = myGroupe.GetIdGroupe();
foreach (string id_grp in liste_id)
{
groupe.Items.Add(id_grp);
}
{
string rsql = "SELECT * FROM groupe";
List<string> liste_id = new List<string>();
try
{
SqlCommand myCommand = new SqlCommand(rsql, CnxBase.myConn);
myCommand.Transaction = CnxBase.trans;
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
liste_id.Add((string)myReader["ID_Groupe"]);
}
myReader.Close();
return liste_id;
}
catch (Exception myErr)
{
throw (new Exception(myErr.ToString()));
}
}
//appel
List<string> liste_id = new List<string>();
liste_id = myGroupe.GetIdGroupe();
foreach (string id_grp in liste_id)
{
groupe.Items.Add(id_grp);
}