Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Crystal Reports VB.net 2010

Posted on 2014-11-07
17
Medium Priority
?
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +1
17 Comments
 
LVL 101

Assisted Solution

by:mlmcc
mlmcc earned 1108 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 224 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 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 668 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 70

Assisted Solution

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

Assisted Solution

by:mlmcc
mlmcc earned 1108 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
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 668 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 101

Assisted Solution

by:mlmcc
mlmcc earned 1108 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 101

Assisted Solution

by:mlmcc
mlmcc earned 1108 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 101

Accepted Solution

by:
mlmcc earned 1108 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 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