Archive for the '.Net' Category

11
Jan
08

Hiding Detail Section In Crystal Reports (.Net)

I’m not a Crystal Report Expert. This article is for newbie only. You can read this article in Indonesian Language too here.

I’ve faced this problem two days ago. If there is any extension data, I have to show it in my report where the number of extension table(s) = extension data.

So, I’ve to put the extension data in a datatable, and locate its fields in Details section of my Crystal Report Designer.

 

Detail Section

 

As its behaviour, when the datatable has 4 records, 4 extension tables printed in my report. When it is 3 records, 3 tables printed.

 

Okay. That’s perfect!! When it is N record(s), N table(s) printed. But I don’t know why. When the datatable empty, N = 0, it printed empty table.

 

 

My boss warned me not to display this extension table template.Warning

 

I’ve browsed report document object properties to find a property which could hide details section, but failed to find the associated property.

 

I’ve googled this problem for hours, but failed to find a solution.

 

So I tried to solve this problem on my own creativity.

 

I made two Crystal Report Template (rpt files): Report.rpt and Report_noExtension.rpt.

 

Report_noExtension.rpt is copied from Report.rpt but with little modification to Detail Section.

Hide a section

Right click on detail section à Section Format à select Details in Section Expert à check Hide (Drill-Down OK) option.

Yeah..!! I can hide this section in Report Designer only.

ATTENTION!! IF YOU CAN DO THIS MODIFICATION IN C# 1.1, PLEASE TELL ME HOW TO DO THAT.

Change this code

Dim rpt As New ReportDocument

rpt.Load(ROOT_RPT + “Report.rpt”)

rpt.SetDataSource(ds)

to be

Dim rpt As New ReportDocument
If datatable.Rows.Count = 0 Then
rpt.Load(ROOT_RPT + “Report_noExtension.rpt”)
Else
rpt.Load(ROOT_RPT + “Report.rpt”)
End If

rpt.SetDataSource(ds)

 

02
Aug
07

Running .dtsx from C#

I figure out this code when I try to run the .dtsx package from C#.
Quite a prospect, I guess. The .dtsx package (Sql Server Integration Service) itself has open many possibilites to do some ETL and Data Warehousing. I won’t cover the ETL Tutorial with SSIS in this post though, I’m still learning on it.

I just want to share the code I made to run simple .dtsx package. When I try searching the tutorial in http://msdn2.microsoft.com/en-us/library/ms136090.aspx I got some errors when I compiled it, therefore I made some slight changes to make it work:

Here is my code:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
namespace MyConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            string pkgLocation;
            
           
            Package pkg;
            Application app;
            DTSExecResult pkgResults;

            pkgLocation =
            @”C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\TheIntegration\TheIntegration\Package.dtsx”;
            app = new Application();
            pkg = (Package)app.LoadPackage(pkgLocation, true, null);
            pkgResults = pkg.Execute();

            Console.WriteLine(pkgResults.ToString());
            Console.ReadKey();
        

          
        }
    }

}

Please note that the location string is the location of your .dtsx file. One more thing, don’t forget to add Microsoft.SQLServer.DTSRuntimeWrap.dll as reference.

Hope it help!




Follow

Get every new post delivered to your Inbox.