Solved

Crystal Reports VB.net 2010

Posted on 2014-11-07
17
571 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
did you check my article?
0
 
LVL 100

Assisted Solution

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

mlmcc
0
 

Author Comment

by:triphen
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I think CR13, but how can I check the exact version?
0
 
LVL 100

Assisted Solution

by:mlmcc
mlmcc earned 277 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
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…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now