1
votes

I test an application with crystal report. I create 1 dataset with 4 tables (master, items, solution, evaluation) and this is my code

            //Master
            dsMaster.Tables["master"].ImportRow(dtMaster.Rows[0]);
            //Items
            DataTable dtItems = getItems(_mdReqMaster.id);
            if(dtItems.Rows.Count > 0){
                foreach(DataRow dr in dtItems.Rows){
                    dsMaster.Tables["items"].ImportRow(dr);
                }
            }                   
            //TeamTech
            DataTable dtTechnicians = getTechnicians(_mdReqMaster.id);
            if (dtTechnicians.Rows.Count > 0)
            {
                foreach (DataRow dr in dtTechnicians.Rows)
                {
                    dsMaster.Tables["technicians"].ImportRow(dr);
                }
            }
            //Solution
            DataTable dtSolution = getSolution(_mdReqMaster.id);
            if (dtSolution.Rows.Count > 0)
            {
                foreach (DataRow dr in dtSolution.Rows)
                {
                    dsMaster.Tables["solutions"].ImportRow(dr);
                }
            }
            //Evaluate
            DataTable dtEvaluate = getEvaluate(_mdReqMaster.id);
            if (dtEvaluate.Rows.Count > 0)
            {
                foreach (DataRow dr in dtEvaluate.Rows)
                {
                    dsMaster.Tables["evaluation"].ImportRow(dr);
                }
            }

Data added see my picture:


        report.Load(Path.Combine(
        HostingEnvironment.MapPath("~/Reports/"), "report.rpt"));

        //report.Database.Tables[0].SetDataSource(dsMaster.Tables[0]);
        //report.Database.Tables[1].SetDataSource(dsMaster.Tables[1]);

        report.SetDataSource(dsMaster);
        report.Refresh();
        Stream stream = report.ExportToStream(ExportFormatType.PortableDocFormat);
    MemoryStream streamReader = new MemoryStream();
    stream.CopyTo(streamReader);

    return streamReader.ToArray();

Output:
I get only data from table master. And when I use Database. Tables[0].SetDataSource(dsMaster.Tables[0]) I get login error, looks like I need to set login to report and I think I don't need to set that because I use dataset. Can someone help me, please? Thank you so much.

2
I think your question may be very similar to this one. - R. McMillan

2 Answers

0
votes

You cant SetDataSource to a table, only to dataset.. If you open your CrystalReport, can you see all your DataTables in DatabaseFields? Try to define Crystal Report details sections for all of your DataTables.. so now you have 4 details sections, and to first section try to put db fields from DataTable1, to second from DataTable2, etc.. Are your data now visible?

0
votes

My problem is me, i'm use another table in sub report then i need to add that data to sub report