Quantcast
Viewing all articles
Browse latest Browse all 3636

How do I get a report and sub report to read from a custom dataset

I have a report and sub-report, where the reports are unrelated so there is nothing to link the two. The mane report works fine. But I want the sub report content to pick up its paragraph from as unrelated selection criteria.

 

 

The main report picks up customer details from the database, no problem, but the letter content is based on the letter type that you pick. The content comes from elsewhere. I could define the letters separately but that means maintaining lots of letters. So I have one letter template (the sub-report) and all the different paragraphs saved in a separate table.

 

 

Data-wise I'm essentially doing two selects but with no join, e.g.

 

 

SELECT * FROM CUSTOMERS WHERE CUSTID='123ABC'

 

 

SELECT Paragraph FROM Paragraphs WHERE LetterType = 'STANDARDLETTER'

 

 

I have tried all manner of clever queries in both MS Access and SQL Server. Neither can yield the required result. So I though I would fill the sub-report from code. Easily done (I thought) as there are many articles that state this can be done.

 

 

However, after reading many articles on here and other websites I came up with the code below as a tester. Looks pretty simple doesn't it. From what I have read this should work but doesn't. It produces nothing but a blank sheet. I have a dataset that the report links to that exactly matches the code below.

 

 

If you can get this to work I will be very impressed indeed. Please only respond with code that you have actually tested and you know to work. Full examples please, no meaningless and out of context snippets (I hate those). Thanks in advance Image may be NSFW.
Clik here to view.

 

 

I am using Visual Studio 2010. Windows 8 x64. Crystal Reports XI. Microsoft Access and Microsoft SQL Server 2008 R2

 

 

    public DataSet MyReportParas(string LetterCode)

    {

        DataSet oDataset = new DataSet();

 

 

        DataTable oTable1 = new DataTable("DataTable1");

        oTable1.Columns.Add("Name");

        oTable1.Columns.Add("Address");

        oTable1.Columns.Add("Ref1");

        oTable1.Columns.Add("Ref2");

        oTable1.Columns.Add("Name2");

 

 

        DataRow oRow = oTable1.NewRow();

        oRow["Name"] = "Mr Fred Bloggs";

        oRow["Address"] = "1 Main Street\r\nFordsham\r\nBristol\r\nBS1 2HY";

        oRow["Ref1"] = "XYZ12345";

        oRow["Ref2"] = "ABC98765";

        oRow["Name2"] = "Fratton and Barnley Ltd";

        oTable1.Rows.Add(oRow);

 

 

        DataTable oTable2 = new DataTable("DataTable2");       

        oTable2.Columns.Add("Paragraph");

 

 

        oRow = oTable2.NewRow();

        oRow["Paragraph"] = "Mary had a little lamb.";

        oTable2.Rows.Add(oRow);

        oRow = oTable2.NewRow();

        oRow["Paragraph"] = "Its fleece was as white as snow.";

        oTable2.Rows.Add(oRow);

 

 

        oDataset.Tables.Add(oTable1);

        oDataset.Tables.Add(oTable2);

 

 

        return oDataset;

    }

 

 

    public void PrintMyLetter()

    {

        CrystalReports.Letter oLetter = new CrystalReports.Letter();

 

 

        DataSet oDataset = MyReportParas("");

 

 

        oLetter.SetDataSource(oDataset);

 

 

        oLetter.Refresh();

 

 

        crystalReportViewer1.ReportSource = oLetter;

 

 

        crystalReportViewer1.Refresh();

 

 

        //default show whole page

        crystalReportViewer1.Zoom(2);

    }


Viewing all articles
Browse latest Browse all 3636

Trending Articles