void PopulateGridview() { DataTable dt = new DataTable(); using (SqlConnection sqlCon = new SqlConnection(connectionString)) { sqlCon.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Client", sqlCon); da.Fill(dt); } if (dt.Rows.Count > 0) { ListeClient.DataSource = dt; ListeClient.DataBind(); } else { dt.Rows.Add(dt.NewRow()); ListeClient.DataSource = dt; ListeClient.DataBind(); ListeClient.Rows[0].Cells.Clear(); ListeClient.Rows[0].Cells.Add(new TableCell()); ListeClient.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count; ListeClient.Rows[0].Cells[0].Text = "No Data Found ..!"; ListeClient.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center; } }
private void rptListeClient_Load(object sender, EventArgs e) { try { ListeClient rpt = new ListeClient(); SqlCommand cmd = new SqlCommand(@"SELECT personne.nom, personne.postnom, personne.prenom, personne.sexe, personne.numeroTel FROM client INNER JOIN personne ON client.id_personne = personne.id", Factory.Instance.connectDB()); SqlDataAdapter sa = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); sa.Fill(ds, "doc"); rpt.SetDataSource(ds.Tables["doc"]); rptListeClientF.ReportSource = rpt; rptListeClientF.Refresh(); sa.Dispose(); ds.Dispose(); cmd.Dispose(); } catch (Exception exc) { MessageBox.Show(exc.Message, "Erreur de l'afichage du rapport", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }