Crystal Reports VB.net 2010

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

triphenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
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
vastoCommented:
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
Éric MoreauSenior .Net ConsultantCommented:
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

triphenAuthor Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
did you check my article?
0
mlmccCommented:
Since you had it working with CRAXDRT did you check the article on converting to the .Net assemblies?

mlmcc
0
triphenAuthor Commented:
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
triphenAuthor Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
instead of having the report connect to the server, I push a data set already filled to the report.
0
mlmccCommented:
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
triphenAuthor Commented:
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
triphenAuthor Commented:
I think CR13, but how can I check the exact version?
0
mlmccCommented:
Do you design in the VS IDE or a separate program?

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

mlmcc
0
triphenAuthor Commented:
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
triphenAuthor Commented:
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
mlmccCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
triphenAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.