elmotardo
Messages postés17Date d'inscriptionlundi 8 octobre 2007StatutMembreDernière intervention29 mai 2008
-
7 mai 2008 à 10:16
elmotardo
Messages postés17Date d'inscriptionlundi 8 octobre 2007StatutMembreDernière intervention29 mai 2008
-
9 mai 2008 à 12:17
bonjour,
je dois faire une requete avec une jointure de 2 tables, quand je fais la requête avec l'outile "requête" proposé par visual studio, ça me donne bien ce que je veux mais quand je fais la même requête dans ma classe c# il n'en veut pas, il rentre bien dans le try mais pas dans la boucle.
voici le code :
oCommand new SqlCommand("SELECT PRODUIT_CHAMP_CUSTOM.*, CHAMPS_CUSTOM.* FROM PRODUIT_CHAMP_CUSTOM INNER JOIN CHAMPS_CUSTOM ON PRODUIT_CHAMP_CUSTOM.CH_ID CHAMPS_CUSTOM.CH_ID WHERE (PRODUIT_CHAMP_CUSTOM.PDT_ID = '"+idProduit+"') AND (PRODUIT_CHAMP_CUSTOM.PRODUIT_CHAMP_CUST_ID <> 28)", _connexion);
try
{
connexion();
ArrayList champsCustom = new ArrayList();
SqlDataReader champCustom = oCommand.ExecuteReader();
while (champCustom.Read())
{
produit.setIngredients("test");
if ( champCustom["PRODUIT_CHAMP_CUSTOM.CHAMP_VALEUR_STRING"] != DBNull.Value )
{
champsCustom.Add(new Double(champCustom["CHAMPS_CUSTOM.CH_NOM"].ToString(), champCustom["PRODUIT_CHAMP_CUSTOM.CHAMP_VALEUR_STRING"].ToString()));
}
}
produit.setChampsCustom(champsCustom);
}
catch
{
}
deconnexion();
elmotardo
Messages postés17Date d'inscriptionlundi 8 octobre 2007StatutMembreDernière intervention29 mai 2008 9 mai 2008 à 08:49
je vais voir pour les requêtes parametrées, merci du conseil.
Quand au champ PRODUIT_CHAMP_CUSTOM.PDT_ID c'est un int tout ce qu'il y a de plus classique
elmotardo
Messages postés17Date d'inscriptionlundi 8 octobre 2007StatutMembreDernière intervention29 mai 2008 9 mai 2008 à 10:16
bon je viens de tester et ça ne donne rien de plus, voici le nouveau code
string sql "SELECT PR.*, CH.* FROM PRODUIT_CHAMP_CUSTOM AS PR INNER JOIN CHAMPS_CUSTOM AS CH ON PR.CH_ID CH.CH_ID WHERE (PR.PDT_ID = @idProduit) AND (PR.PRODUIT_CHAMP_CUST_ID <> @idNonVoulu)";
SqlCommand cmd = new SqlCommand(sql,_connexion);
DbParameter paramIdProduit = cmd.CreateParameter();
paramIdProduit.ParameterName = "@idProduit";
paramIdProduit.DbType = DbType.Int32;
paramIdProduit.Value = int.Parse(idProduit);
elmotardo
Messages postés17Date d'inscriptionlundi 8 octobre 2007StatutMembreDernière intervention29 mai 2008 9 mai 2008 à 12:06
j'ai "catché" les exceptions et voilà ce que ça me donne ->
Une exception de première chance de type 'System.Data.SqlClient.SqlException' s'est produite dans System.Data.dll
Une exception de première chance de type 'System.InvalidOperationException' s'est produite dans System.Data.dll