Probleme de connection de combobox à la base de données

cs_amal2008 Messages postés 13 Date d'inscription vendredi 7 septembre 2007 Statut Membre Dernière intervention 30 août 2009 - 1 mars 2009 à 21:58
RougailSaucisse Messages postés 118 Date d'inscription lundi 16 février 2009 Statut Membre Dernière intervention 6 décembre 2010 - 2 mars 2009 à 00:03
salut,


je realise une application en c# en utilisant sqlserver
voilà mon code du fichier App.config


<?xmlversion="
1.0"
encoding="
utf-8"
?>


<configuration>


<connectionStrings>


<addname="
dbpamSqlServer2005"
connectionString="
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\labase\dbpam.mdf;User Id=op;password=op;Connect Timeout=30;"







providerName
=
"

System.Data.SqlClient
"

/></


connectionStrings
><


appSettings
><


add


key
=
"

selectEmploye
"



value
=
"

selectNOM,PRENOM,ADRESSE,VILLE,CODEPOSTAL,EMPLOYES.INDICE,BASEHEURE,ENTRETIENJOUR,REPASJOUR,INDEMNITESCP

from EMPLOYES,INDEMNITES where SS=@SS and EMPLOYES.INDICE=INDEMNITES.INDICE


"

/><


add


key
=
"

selectEmployes
"



value
=
"

select PRENOM, NOM, SS from EMPLOYES
"

/><


add


key
=
"

selectCotisations
"



value
=
"

select CSGRDS,CSGD,SECU,RETRAITE from COTISATIONS
"

/></


appSettings
></


configuration
>

mon but c'est d'afficher à partir du combobox les noms des emploées et pour celà voilà mon code:
using

System;
using

System.Collections.Generic;
using

System.ComponentModel;
using

System.Data;
using

System.Drawing;
using

System.Text;
using

System.Windows.Forms;
using

System.Configuration;
namespace

proj1{

public
partial
class
Form1 :
Form{

// données du formulaire

private
string connectionString;

private
string selectEmploye;

private
string selectEmployes;

private
string selectCotisations;

private
string msgErreur =
null;

public Form1(){

InitializeComponent();

try {
// chaîne de connexion

connectionString =

ConfigurationManager.ConnectionStrings[
"dbPamSqlServer2005"].ConnectionString;
// ordres select

selectEmploye =

ConfigurationManager.AppSettings[
"selectEmploye"];selectEmployes =

ConfigurationManager.AppSettings[
"selectEmployes"];selectCotisations =

ConfigurationManager.AppSettings[
"selectCotisations"];}

catch {

// configuration erronéemsgErreur =

"Erreur de configuration dans [App.config]";}

}

private
void button1_Click(
object sender,
EventArgs e){

label4.Text = textBox1.Text + textBox2.Text;

}

private
void Form1_Load(
object sender,
EventArgs e){

comboBox1.DataSource = selectEmployes;
comboBox1.DisplayMember "NOM";comboBox1.ValueMember

"SS";}

}

}
mais je recoi l'erreur suivante et le combobox n'affiche rien:

DataBinding complexe accepte IList ou IListSource comme source de données.
l'exception argumentexception n'a pas été géneré
ma question c'est
qui est le code que je doit associer à combobox pour qui se lie à la base et par suite afficher les noms des emplyes
merci

3 réponses

cs_amal2008 Messages postés 13 Date d'inscription vendredi 7 septembre 2007 Statut Membre Dernière intervention 30 août 2009
1 mars 2009 à 23:37
est ce que quelqu un a une idée pour la solution de ce probleme
0
RougailSaucisse Messages postés 118 Date d'inscription lundi 16 février 2009 Statut Membre Dernière intervention 6 décembre 2010 1
2 mars 2009 à 00:02
Tu bind une string à ton combobox c'est normal que cela ne fonctionne pas. Il te faut aller récuperer tes données dans la database grace à cette chaine que tu recuperes puis bind le résultat a ta combobox. Pour cela regarde comment fonctionne ADO.net (datatable, dataset...), le net est inondé d'infos a ce sujet. une fois que t'aura compris comment fonctionne ne serait-ce qu'un dataset, tu pourras facilement bind les resultats de ta requete a ta combobox et de preference dans un isPostback

privatevoid Form1_Load(
object sender,
EventArgs e){

if(!isPostBack)

{

DataSet ds = new DataSet();

[...] //ton code ADO.net de sélection

comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember "NOM";comboBox1.ValueMember     

"SS";
}
}
0
RougailSaucisse Messages postés 118 Date d'inscription lundi 16 février 2009 Statut Membre Dernière intervention 6 décembre 2010 1
2 mars 2009 à 00:03
oups my mistake, je pensais etre sur le forum asp.net donc evidemment oublie l'histoire du IsPostBack ^^
0
Rejoignez-nous