Assignation mal comprise

Fermé
mewaketgueu Messages postés 37 Date d'inscription vendredi 6 mars 2009 Statut Membre Dernière intervention 10 novembre 2015 - 16 janv. 2014 à 11:40
xROOSIE Messages postés 80 Date d'inscription vendredi 29 avril 2011 Statut Membre Dernière intervention 25 février 2017 - 26 févr. 2014 à 12:30
Salut tout le monde
svp j'ai des soucis de compréhension avec ce bout de code
wc est un string null ok
mais kan on met wc += ..... comme cela est ecrit dans mon code qu 'est ce que cela signifie?
le " LIKE @LIBELLE " je ne les comprends pas non plus
merci d'avance

voici le bout de code en bas

public class MEEntreprise : METable<Entreprise>
{
public List<Entreprise> Recherche(string Libelle)
{
string wc = null;
DataParameterCollection parameters = new DataParameterCollection();

if (!string.IsNullOrEmpty(Libelle))
{
wc += ((!string.IsNullOrEmpty(wc)) ? " AND " : null) + "((entreprise.RAISONSOCIALE LIKE @LIBELLE) OR (entreprise.NOMCOMMERCIAL LIKE @LIBELLE))";
parameters.Add(new DataParameter("@LIBELLE", string.Format("%{0}%", Libelle)));//%{0}% pour rechercher tous les enregistrement qui utilisent le caractère representé par {0}.
}

return this.ModelContext.Operator.ExecuteList<Entreprise>(new SqlStatement(string.Format("SELECT entreprise.* FROM entreprise {0}", (!string.IsNullOrEmpty(wc)) ? " WHERE " + wc : null), parameters));
}
}

public static class MEEntrepriseExtend
{
public static Entreprise Entreprise(this Intervenant Intervenant)
{
return (new MEEntreprise()).SelectionnerParId(Intervenant.IDENTREPRISE);
}
public static Entreprise Entreprise(this Materiel Materiel)
{
return (new MEEntreprise()).SelectionnerParId(Materiel.IDENTREPRISE);
}
}

1 réponse

xROOSIE Messages postés 80 Date d'inscription vendredi 29 avril 2011 Statut Membre Dernière intervention 25 février 2017 247
26 févr. 2014 à 12:30
Bonjour (je répond un peu tard) que vous mettez wc="bonjour" donc la variable est égale à bonjour
string wc ="bonjour"
wc=lol 
// la premère déclaration avec "bonjour est écrasée  du coup :
Console.writeLine(wc) //affiche lol

Si tu mets
string wc="bonjour"
wc+="lol"
Console.WriteLine(wc) //cela ne va rien écraser, ça affiche "bonjourlol"
0