Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 741
  • 922
  • 41.6k

Sorted data doesn't show on the print preview

Apr 19 2024 5:48 PM

Hello Team,
In my window form project, am able to sort the data between dates range on the dataGridView but the sorted data doesn't show on the print Preview, but the print Preview print all the data from the database

// this is the prnt button on the DataGridView page;
 private void pictureBox11_Click(object sender, EventArgs e)
        {
          frmFirstTimersReport frm = new frmFirstTimersReport(this);
          LoadFirstTimersReportByDate(); 
          frm.LoadFirstTimers(); // this code reference report printview page;          
          frm.Show();
        }


// this code is for sorting data between dates range and is on the DataGridView page;
 public void LoadFirstTimersReportByDate()
        {
            int i = 0;
            dataGridView5.Rows.Clear();
            cn.Open();
            cm = new SqlCommand("Select * from tblFirstTimers where FDate between @StartDate and @EndDate", cn);
            cm.Parameters.AddWithValue("@StartDate", FirstTimersDt1.Value.Date);
            cm.Parameters.AddWithValue("@EndDate", FirstTimersDt2.Value.Date);
            dr = cm.ExecuteReader();
            while (dr.Read())
            {
                i++;
                dataGridView5.Rows.Add(i, dr["id"].ToString(), dr["FDate"].ToString(), dr["FName"].ToString(), dr["LName"].ToString(), dr["FGender"].ToString(), dr["FDOB"].ToString(), dr["FLocation"].ToString(), dr["FPhoneNo"].ToString(), dr["FInvitedBy"].ToString(), dr["FPrayerRequest"].ToString());
            }
            dr.Close();
            cn.Close();

        }


// this code is on the reportView Page ;

public void LoadFirstTimers()
        {
            ReportDataSource rptDataSource;
            this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\rptFirstTimers.rdlc";
            this.reportViewer1.LocalReport.DataSources.Clear();
            DataSet1 ds = new DataSet1();
            SqlDataAdapter da = new SqlDataAdapter();
            cn.Open();
            da.SelectCommand = new SqlCommand("select * from tblFirstTimers", cn);
            da.Fill(ds.Tables["dtFirstTimers"]);
            rptDataSource = new ReportDataSource("DataSet1", ds.Tables["dtFirstTimers"]);
            reportViewer1.LocalReport.DataSources.Add(rptDataSource);
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = ZoomMode.Percent;
            reportViewer1.ZoomPercent = 100;

            cn.Close();
        }


Answers (4)