3 Jan 2007

Display a drill down report

Fist of all writeb these lines on top of your code

Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared


A procedure is given below to display a drill down enabled crystal report.Although same procedure has been used to display a simple report but that used Load method of crystal report object.And if used that method of crystalreport document then drilldown will not work.After making some necessary changes it will work fine.

Private Sub ShowReport()
Dim str_L_Sql As String
Dim dr As SqlDataReader
Dim cmd As New SqlCommand
Dim MyReport As New CrystalReportSource
Dim conn As New SqlConnection(strCon)
Try
Dim path As String = Server.MapPath(CStr(Session("RepPath") & str_P_ReportName))

'here Session("RepPath") contains report path and variable str_P_ReportName contains crystalreport name
CrystalReportViewer1.ReportSource = Nothing 'To initialize reportsource of viewer
MyReport.Report.FileName = path
MyReport.CacheDuration = 1 'This is must so because default cache duration is zero and if this 'property is zero then report will display same as fist display on each refresh means parameters 'change will not effect.To set this proprty 1 sec means cache will be only 1 second.
CrystalReportViewer1.ReportSource = MyReport

'My report is a CrystalReportSource which is assigned dynamically to viewer.This will tell that 'which one report will be display in viewer
'Below lines is used to pick parameters from database.If u have static parameters then adjust 'accordingly and do'nt interact with database to assign report parameters
str_L_Sql = "Select param_Name,orderNo from tbl_Report_D where report_ID=(Select report_ID from tbl_Report_M where report_Name='" & str_P_ReportName & "') order by orderNo"
conn.Open()
With cmd
.CommandType = CommandType.Text
.CommandText = str_L_Sql
.Connection = conn
End With
dr = cmd.ExecuteReader()
CrystalReportViewer1.ParameterFieldInfo = Nothing
While dr.Read()
If CStr(Session(dr.Item(0).ToString)) <> "" Then
crParameterFields = CrystalReportViewer1.ParameterFieldInfo
crParameterField = crParameterFields.Item(CInt(dr.Item(1).ToString) - 1)
crParameterValues = crParameterField.CurrentValues
crParameterDiscreteValue = New ParameterDiscreteValue()
crParameterDiscreteValue.Value = Session(dr.Item(0).ToString)
crParameterValues.Add(crParameterDiscreteValue)
End If
End While
CrystalReportViewer1.ParameterFieldInfo = crParameterFields
With crconnectioninfo
.ServerName = Session("SName")
.DatabaseName = Session("DBName")
.UserID = Session("Uid")
.Password = Session("Pwd")
End With
CrystalReportViewer1.LogOnInfo.Item(0).ConnectionInfo = crconnectioninfo
'CrystalReportSource1.ReportDocument.SummaryInfo.ReportTitle = Session("ReportTitle")
'CrystalReportViewer1.RefreshReport()
dr.Close()
conn.Close()
cmd = Nothing
Catch
lblMessage.Visible = True 'To show error message if any error occured
lblMessage.Text = Err.Description
End Try
End Sub

5 comments:

Anonymous said...

Dude stop plagiarizing !! Do you lack originality ?

K.K. Gaurav said...

Whats ur means by originality

Anonymous said...

Dear Author kkgaurav.blogspot.com !
I apologise, but, in my opinion, you commit an error. I can prove it.

K.K. Gaurav said...

Hi Friend,

I copy this code from my developement environment and this was working fine there. It can be that there be any problem and the user of this code need to modify accordingly. If you have identified any problem then tell me, I will update the topic.

Anonymous said...

Hi!
You may probably be very interested to know how one can manage to receive high yields on investments.
There is no initial capital needed.
You may commense earning with a sum that usually goes
on daily food, that's 20-100 dollars.
I have been participating in one project for several years,
and I'll be glad to share my secrets at my blog.

Please visit blog and send me private message to get the info.

P.S. I make 1000-2000 per day now.

http://theinvestblog.com [url=http://theinvestblog.com]Online Investment Blog[/url]