Solved

Crystal Reports VB.net 2010

Posted on 2014-11-07
17
591 Views
Last Modified: 2014-11-13
Hello Experts,

I am rewriting an app in VB.net from VB6. Here is my code to generate a Crystal Report in VB6. I cant get figure out how to make this work in VB.net 2010. Can someone point me in the right direction?

Private Sub SetReportLocation(ByRef RepObj As CRAXDRT.Report)

    Dim CrxDDF As CRAXDRT.DatabaseTable
    Dim CP As CRAXDRT.ConnectionProperties

    For Each CrxDDF In RepObj.Database.Tables
        Set CP = CrxDDF.ConnectionProperties
        CP.DeleteAll
        CP.Add "ConnectionString", "Driver={SQL Anywhere 10};Uid=user;Pwd=password;DSN=sqlbase;"

    Next

    Set CrxDDF = Nothing
    Set CP = Nothing

End Sub


Private Sub cmd_Print_Click()

Dim DetailPrnt As VbMsgBoxResult
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report

DetailPrnt = MsgBox("Would you like a detailed print?", vbYesNo, "Detailed?")

If DetailPrnt = vbYes Then
    Set crxApp = New CRAXDRT.Application
    Set crxRpt = crxApp.OpenReport(App.Path & "\Reports\DetailRecpt.rpt")
    SetReportLocation crxRpt
    crxRpt.ParameterFields(1).AddCurrentValue (txt_Transact.Text)
Else
    Set crxApp = New CRAXDRT.Application
    Set crxRpt = crxApp.OpenReport(App.Path & "\Reports\StdRecpt.rpt")
    SetReportLocation crxRpt
    crxRpt.ParameterFields(1).AddCurrentValue (txt_Transact.Text)
End If

'To View the report
frm_Report.Show
frm_Report.CRViewer.ReportSource = crxRpt
frm_Report.CRViewer.ViewReport



End Sub

Open in new window

0
Comment
Question by:triphen
  • 8
  • 5
  • 3
  • +1
17 Comments
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40428280
You can't make that code work in VB2010.

The RDC (CRAXDRT) has been replaced with .Net assemblies and won't work.  It is still available on your system for some kind of backwards compatibility.

You need to download Crystal for VS2010
http://scn.sap.com/people/coy.yonce/blog/2010/11/12/crystal-reports-for-visual-studio-2010-production-release-now-available

Here is a document that explains how to migrate from the RDC to .Net
http://scn.sap.com/docs/DOC-21971

http://msdn.microsoft.com/en-us/library/ms225492(v=vs.80).aspx

mlmcc
0
 
LVL 18

Assisted Solution

by:vasto
vasto earned 56 total points
ID: 40428774
Agree. Some basic features in CRAXDRT might be working in VB.NET, but there will be tons of problems and as far as I know the license is not allowing it.
0
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40429371
you better try the version of CR that is specifically built for .Net. Have a look at http://emoreau.com/Entries/Articles/2006/09/Feeding-Crystal-Reports-from-your-application.aspx
0
 

Author Comment

by:triphen
ID: 40429518
Thanks for the feedback...I downloaded Crystal for VS2010, but still kind of lost :/

How do I set my connection string? How do I pass parameters?
0
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40429749
did you check my article?
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40430240
Since you had it working with CRAXDRT did you check the article on converting to the .Net assemblies?

mlmcc
0
 

Author Comment

by:triphen
ID: 40432023
I read both articles, but it is still unclear on where to put my connection string. Can you point me in the right direction?
0
 

Author Comment

by:triphen
ID: 40432032
This is my current code:

Dim cryRpt As New ReportDocument
cryRpt.Load("C:\Reports\Report.rpt")
CrystalReportViewer1.ReportSource = cryRpt

Open in new window


All this is doing is loading the RPT file in the CrystalReportViewer1, and it appears to load data that was saved to the actual RPT file when the RPT was first created. I catn figureout how to make it connect to the DSN using this connection string:

"Driver={SQL Anywhere 10};Uid=user;Pwd=password;DSN=sqlbase;"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
ID: 40432416
instead of having the report connect to the server, I push a data set already filled to the report.
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40432769
What version of Crystal are you using?

If it is a standalone version, does the report run from the designer?

Have you tried to refresh the report?


mlmcc
0
 

Author Comment

by:triphen
ID: 40434233
When I added "CrystalReportViewer1.RefreshReport()" I get a prompt for my Crystal Reports parameters, then a prompt for login credentials. See attached.

Dim cryRpt As New ReportDocument
       cryRpt.Load("C:\Reports\Report.rpt")
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.RefreshReport()

Open in new window

0
 

Author Comment

by:triphen
ID: 40434234
I think CR13, but how can I check the exact version?
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
ID: 40434273
Do you design in the VS IDE or a separate program?

IN the standalone version it is under HELP --> ABOUT CRYSTAL

mlmcc
0
 

Author Comment

by:triphen
ID: 40434277
I am designing the report in a completely separate program. See attached.

Then I am trying to open it using a Windows Form applciation on VS 2010 VB.net
0
 

Author Comment

by:triphen
ID: 40434420
So I got it to login and pass a parameter, but for some reason on loading of the report, I get a prompt that asks me for the parameter again?

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1



   
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument



        cryRpt.Load("C:\Reports\StdRecpt.rpt")


        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = "71744"
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("Transact")
        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)


        CrystalReportViewer1.ReportSource = cryRpt
        cryRpt.SetDatabaseLogon("user", "password", "sqlbase", "")
        CrystalReportViewer1.RefreshReport()
End Sub

Open in new window

0
 
LVL 100

Accepted Solution

by:
mlmcc earned 277 total points
ID: 40434962
Which version of Crystal?

Don't do a refresh.  That causes Crystal to discard the parameters and prompt again.

Make sure the report is NOT saved with data
Open the report
Click FILE
Uncheck SAVE DATA WITH REPORT

mlmcc
0
 

Author Comment

by:triphen
ID: 40442024
THIS WORKED!!!!


        Dim cryRpt As New ReportDocument
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        cryRpt.Load("C:\Reports\StdRecpt.rpt")

        crParameterDiscreteValue.Value = "71745"
        crParameterFieldDefinitions = _
        cryRpt.DataDefinition.ParameterFields
        crParameterFieldDefinition = _
        crParameterFieldDefinitions.Item("Transact")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

        CrystalReportViewer1.ReportSource = cryRpt

        cryRpt.SetDatabaseLogon("username", "password", "DSN NAME", "")
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
No row return after calling the fillschema method 4 39
VB.Net - For Loop Error 5 32
Saveas need to save a copy 16 26
Cyrstal Reports formula to check IsNull 8 22
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now