Je voudrai remplir mon datagridview2 en fonction d'une donnée que je recupère dans un datagridview1. voilà les différentes étapes.
Merci de me venir en aide je vous en prie
je traîne ce pb depuis une semaine. j'ai tout éssayé.
/********************************************************/
Ma requête sql (Procedure stockée)
/********************************************************/
/********************************************************/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 ALTER PROCEDURE dbo.SP_GetEmployeByEntreprise ( @NomEntreprise nvarchar(50) ) AS SELECT e.Nom,e.Prenom,e.Age,q.LibelleQualification,ese.NomEntreprise FROM EMPLOYE e, ENTREPRISE ese,QUALIFICATION q WHERE e.IdQualification=q.IdQualification AND e.IdEntreprise=ese.IdEntreprise AND ese.NomEntreprise=@NomEntreprise /* SET NOCOUNT ON */ RETURN
ma fonction de conection à la base de données
/********************************************************/
/********************************************************/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 private static string GetConnexion() { string ConnString = ""; try { ConnString = @"Data Source=EMILEPORTABLE\SQLEXPRESS;Initial Catalog=DBGroupeWal;Integrated Security=True"; } catch (Exception) { } return ConnString; }
ma fonction DataSet
/********************************************************/
/********************************************************/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public static DataSet GetEmployeByEntreprise(string nomEntreprise) { DataSet ds = new DataSet(); string ConnString = GetConnexion(); SqlConnection sqlconnection = null; if (ConnString != "") { try { sqlconnection = new SqlConnection(ConnString); SqlCommand sqlcmd=new SqlCommand("SP_GetEmployeByEntreprise",sqlconnection); sqlcmd.CommandType=CommandType.StoredProcedure; sqlcmd.Parameters.Add(new SqlParameter("@NomEntreprise",nomEntreprise)); DataAdapter dt=new SqlDataAdapter(sqlcmd); dt.Fill(ds); } catch (Exception e) { Console.Out.WriteLine(e.Message); } } return ds; }
Le remplissage de mon Datagrid dans la list Form correspondant à l'évènement CellContentClick
/********************************************************/
Affiche_EntrepriseDataGridView: contient un élément que je vais recupérer pour passer en paramètre dans GroupeWal.Employe.GetEmployeByEntreprise(nomEntreprise) que je vais mettre comme source de données avec Affiche_EmployeByEntrepriseDataGridView;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 private void Affiche_EntrepriseDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { //Recupère le numero de la ligne courante int i = Affiche_EntrepriseDataGridView.CurrentCell.RowIndex; //recupère le nom de l'entreprise avec en paramètre le numero de la cellule courante string nomEntreprise = (string)Affiche_EntrepriseDataGridView.Rows[i].Cells[1].Value; //Affiche des noms des employés en fonction de l'entreprise recupéré plus haut. this.Affiche_EmployeByEntrepriseDataGridView.DataSource=GroupeWal.Employe.GetEmployeByEntreprise(nomEntreprise); }
pour être plus clair je voudrai afficher dans le datagridview2 par exemple la liste de toutes les données correspondantes à une donnée se trouvant dans le datagridview2 en reponse à l'évènement CellContentClik du datagridView1
Merci de me venir en aide je vous en prie
Partager