Search code examples
c#crystal-reports

Only show header data but not show details data on dataset (crystal report c#)


I want to show crystal report on dât but it's only show header without show details data

I use dataset to show data but it's not show details data

I created dataset and link to crystal report... It worked when I tried it at Main Report Preview

Please see images: https://i.sstatic.net/HZYEE.png

 crpQLVT rpt = new crpQLVT();
 SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-FFIKNAO\SQLEXPRESS;Initial Catalog=QLVT;Integrated Security=True";);
 conn.Open();
 SqlDataAdapter dap = new SqlDataAdapter("Select * from ThanhPhan", conn);
 DataSet ds = new DataSet();
 dap.Fill(ds);
 rpt.SetDataSource(ds.Tables[0]);
 crystalReportViewer1.ReportSource = rpt;

and result https://i.sstatic.net/NShUN.png

Please help me fix it ! Thanks for help !


Solution

  • 1) Check if connectionString is valid and point to database that you want.

    2) You have to refresh your crystal report viewer after assigning report source to it like

    crpQLVT rpt = new crpQLVT();
    SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-FFIKNAO\SQLEXPRESS;Initial Catalog=QLVT;Integrated Security=True";);
    con.Close();  //close if existing connection open
    con.Open();
    string cmdText = "Select * from ThanhPhan";
    cmd = new SqlCommand(cmdText, con);
    dr = cmd.ExecuteReader();
    DataTable dt = new DataTable();
    dt.Load(dr);
    
    rpt.SetDataSource(dt);
    crystalReportViewer1.ReportSource = rpt;
    crystalReportViewer1.Refresh();
    con.Close();