2
votes
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Linq
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table


        cryRpt.Load("C:\Users\dad\Desktop\report\myfile2.rpt")


        With crConnectionInfo
            .ServerName = "127.0.0.1"
            .DatabaseName = "xxx"
            .UserID = "sa"
            .Password = "123456"
        End With

        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next

        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.Refresh()
    End Sub
End Class

I am getting the below error while trying to load crystal report in visual studio 2013.

An unhandled exception of type 'CrystalDecisions.Shared.CrystalReportsException' occurred in CrystalDecisions.CrystalReports.Engine.dll

Additional information: Load report failed.

On this line cryRpt.Load("C:\Users\dad\Desktop\report\myfile2.rpt")

The path is correct.

3

3 Answers

1
votes

You can try variant

Report.Load(ReportTemplateFullName, _
    CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy)
0
votes

I don't know if it works now, but I put the link where the report is, in a String, so

purchdocReport = New ReportDocument()

Dim reportPath As String = "C:\...\report\purchase_inv1.rpt" purchdocReport.Load(reportPath)

0
votes

Try this... I think you should be happy if you try this one!

Imports CrystalDecisions.CrystalReports.Engine
Imports System.IO
Public Class Form1

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim cryReport As New ReportDocument
Dim strreportpath As String = Path.GetFullPath( _
Path.Combine(Application.StartupPath, "Your Report Location")) & _
        "\sample.rpt"

    cryReport.Load(strreportpath)
    If lvFemale.SelectedItems(0).Text <> "" Then
        cryReport.RecordSelectionFormula = "{tbl_Sample.sampleID} = " & ListView.SelectedItems(0).Text
    End If
    FORM1.CrystalReportViewer1.ReportSource = cryReport
    FORM1.CrystalReportViewer1.Refresh()
End Sub
End Class