Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 1st, 2006, 10:46 AM
Registered User
Join Date: Nov 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.NET - creating a CR report at run time


I have been trying to create crystal reports at run time through VB.NET. What I mean by this is writing the all the code to build a report in VB.NET then passing it to CR Viewer. I am trying to create a report generator where a user would choose columns, filters and group-by's from a VB.NET GUI then run the report based on the user's selection.

I need to send a SQL Query to cyrstal reports and then add the selected columns all at runtime and I haven't a clue how to do this. After searching the internet for a while help seems to be very limited for this problem. I've found small bits of code but it's mainly for ASP or vb6 and I can't get any of it to work!!

I am running CR 9, the version that comes with Visual Studio 2005 and the data is stored in a sybase database (sql based).

If anyone has been able to do this or something similar which could help me, please post some code!!!

Thanks for your help in advance.

Old November 7th, 2006, 12:21 PM
Registered User
Join Date: Nov 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

I'll reply to my own post seen as no-one else has :(

I'm quite sure many people have this problem...

I found out what the problem was - You need a lisence to create Custom reports at runtime. Using the following working code vb.net told me this:

    Dim app As New CRAXDRT.Application
    Dim repdoc As CRAXDRT.Report

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        repdoc = app.NewReport
        'repdoc = New CRAXDRT.Report

        ' Open the data connection
        Dim ADOConnection As New ADODB.Connection
        ADOConnection.Provider = "ASAProv"
        ADOConnection.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=DOB"
        ADOConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient

        ' Create a new instance of an ADO command object
        Dim ADOCommand As New ADODB.Command
        ' ADOCommand.ActiveConnection = New ADODB.Connection
        ADOCommand.CommandText = "Customer"
        ADOCommand.CommandType = ADODB.CommandTypeEnum.adCmdTable

        ' Add the data source (patient table) to the report
        repdoc.Database.AddADOCommand(ADOConnection, ADOCommand.CommandText)
        'Add a title to the report
        repdoc.Sections(1).AddTextObject("Patient Test Report", 6000, 400)

        ' Add fields to details section
        ' Note that the Sections collection can be accessed via
        ' number or string index
        repdoc.Sections("D").AddFieldObject("{ado.sname}", 750, 5)
        repdoc.Sections("D").AddFieldObject("{ado.fname}", 3150, 5)
        repdoc.Sections("D").AddFieldObject("{ado.dob}", 5500, 5)
        repdoc.Sections("D").AddFieldObject("{ado.adr1}", 8850, 5)

        CRViewer91.ReportSource = repdoc

    End Sub

Old November 16th, 2006, 04:41 AM
Registered User
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Even I'm working on a requirement that is something very much similar. I didnt understand what you meant by "You need a lisence to create Custom reports at runtime"..?

Can you give me more details as to ..what reference to add, namespaces to be imported..

Thanking you in anticipation..


Old February 12th, 2008, 09:29 AM
Registered User
Join Date: Nov 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

What I meant was you CANNOT do this with the free version of Crystal you get with VS2005. In order to dynamically set-up a data set you must purchase a developer license from business objects which costs a lot. Then for every user you then deploy the application to another license for each of them is required!

To do this kind of thing use Microsoft RDLC and report viewer that come with VS 2005. Hope this helps anybody in the same situation!!

Old March 21st, 2013, 10:01 AM
Registered User
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Wink VB.NET - creating a CR report at run time

I have good experience in create report with crystal report in design runtime
you can ask me personally in riyadia82@gmail.com or contact on +6285743784380 (Indonesia)
I could help you free
This code is work well in my application

Imports System.Data


Imports ADODB

Public Class RptPrive
Dim DbPrive As New ADODB.Connection
Dim CmdPrive As New ADODB.Command

Dim app As New CRAXDRT.Application
Dim Xreport As CRAXDRT.Report

Private Sub DataSource()


CmdPrive = New ADODB.Command()
CmdPrive.ActiveConnection = DbPrive

CmdPrive.CommandType = CommandTypeEnum.adCmdText
Xreport.Database.AddADOCommand(DbPrive, CmdPrive)

End Sub
Private Sub RptPrive_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

app = New CRAXDRT.Application
Xreport = app.NewReport


Xreport.Sections("D").AddFieldObject("{ADO.KD_PRIV E}", 750, 5)
Xreport.Sections("D").AddFieldObject("{ado.NAMA}", 3150, 5)
Xreport.Sections("D").AddFieldObject("{ado.ALAMAT} ", 5500, 5)
Xreport.Sections("D").AddFieldObject("{ado.NO_TELE PHON}", 8850, 5)

CrvPrive.Top = 0
CrvPrive.Height = Me.Height
CrvPrive.Width = Me.Width

Xreport.PaperSize = CRPaperSize.crPaperLegal

CrvPrive.ReportSource = Xreport


End Sub

Last edited by ARiyadi; March 21st, 2013 at 10:08 AM..

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recipe to change CR query at run time. dbron Crystal Reports 4 June 24th, 2009 03:07 AM
Control resize and positioning at run time. VB.Net TechNik .NET Framework 2.0 5 November 14th, 2008 09:00 AM
How to change CR 11 database name at run time, ASP enghok Classic ASP Professional 3 September 26th, 2007 03:28 AM
change database location on CR 10 at run time blu3_x30n Pro VB 6 0 March 30th, 2006 01:25 PM
Change picture at run-time with CR for .NET? NTurnbullJr Crystal Reports 2 March 31st, 2005 05:29 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.