Select count

Résolu
tabarrant Messages postés 40 Date d'inscription lundi 21 novembre 2005 Statut Membre Dernière intervention 27 octobre 2008 - 8 janv. 2006 à 14:25
tabarrant Messages postés 40 Date d'inscription lundi 21 novembre 2005 Statut Membre Dernière intervention 27 octobre 2008 - 5 févr. 2006 à 04:27
salut a tous et bonne année;



ben voila j'ai un petit probleme , j'aimerais récupérer le résultat d'une instruction SQL.

petit exemple:



j'écris l'instruction

==> string strcmd = "select count(*) from
ENTREPRISE where DenomEntr = '" + comboBox1.Text + "';"; et j'aimerais
récupérer la valeur du compteur.

3 réponses

Homerrrrr Messages postés 22 Date d'inscription mercredi 23 novembre 2005 Statut Membre Dernière intervention 22 février 2006
8 janv. 2006 à 15:04
Tu fais un truc du genre :

ChaineConnection= "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" + "Integrated Security=SSPI;";

OleDbConnection connection = new OleDbConnection(ChaineConnection);
string strcmd "select count(*) from ENTREPRISE where DenomEntr '" + comboBox1.Text + "'";

OleDbCommand commande= new OleDbCommand(strcmd,connection);

connection.Open();
int compteur = commande.ExecuteScalar();
connection.Close();

Et voilà, ton nombre de lignes est contenue dans la variable "compteur";
3
tabarrant Messages postés 40 Date d'inscription lundi 21 novembre 2005 Statut Membre Dernière intervention 27 octobre 2008
10 janv. 2006 à 19:33
merci
0
tabarrant Messages postés 40 Date d'inscription lundi 21 novembre 2005 Statut Membre Dernière intervention 27 octobre 2008
5 févr. 2006 à 04:27
excuser pour avoir acceptée la réponse mais j'étais en exam, mais bon voila c'est fait!

Merci Homerrrrr
0
Rejoignez-nous