Skip to Content
0
Former Member
Dec 21, 2016 at 02:06 PM

The line... rd.SetDataSource(ds) throws many errors

363 Views

    Public Function CreateReport(lxReportXml As String, lcFileName As String, lcReport As String) As Boolean

        Dim rd As ReportDocument = Nothing
        Dim llError As Boolean = False
        Dim IsRoutineSuccessful As Boolean = False
        Dim lcFileNameTo As String = String.Empty
        Dim ds As New DataSet()

        Dim filePath As String = lxReportXml

        ds.ReadXml(filePath, XmlReadMode.Auto)

        If lcFileName = "" Then
            writelog("[ERR]   No PDF file specified")
            llError = True
        End If

        If lxReportXml = "" Then
            writelog("[ERR]   No XML file specified")
            llError = True
        End If

        If lcReport = "" Then
            writelog("[ERR]   No Crystal Report file specified")
            llError = True
        End If

        If llError = False Then
            Dim strErrorMessage As String = String.Empty
#If DEBUG Then
            Dim strReportPath As String = CrystalFilesTesting + lcReport + ".rpt"
#Else
                    Dim strReportPath As String = CrystalFiles + lcProcName + ".rpt"
#End If
            If Not (File.Exists(strReportPath)) Then
                writelog("[ERR]   Crystal Report File [" + strReportPath + "] not found.")
                IsRoutineSuccessful = False
            Else
                rd = New ReportDocument()
                If True Then
                    Try
                        rd.Load(strReportPath)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                        rd.SetDataSource(ds)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                        rd.ExportToDisk(ExportFormatType.PortableDocFormat, lcFileName)
                    Catch ex As Exception
                        writelog("[ERR]  Unable to create file [" + lcFileName + "].  Error: " + ex.ToString)
                        IsRoutineSuccessful = False
                    Finally
                        writelog("File [" + lcFileName + "] created Successfully")
                        rd.Close()
                        rd.Dispose()
#If DEBUG Then
                        lcFileNameTo = "\\WGO\sys2\HOME\wilbir\wilbirmail\WilbirHR\EmplAppPDF\Testing\" + lcLastName + "_" + lcPDFDate + ".pdf"
#Else
                    lcFileNameTo = "\\WGO\sys2\HOME\wilbir\wilbirmail\WilbirHR\EmplAppPDF\" + lcLastName + "_" + lcPDFDate + ".pdf"
#End If
                        File.Copy(lcFileName, lcFileNameTo, True)
                        IsRoutineSuccessful = MailSend(lcFileName)
                    End Try
                End If
            End If
        End If
        Return IsRoutineSuccessful
    End Function

The line...  rd.SetDataSource(ds)  throws many errors, however if I go to the Crystal Report and set the Data Source manually, it works without error.  I have updated to Crystal Reports 2016 without any resolution.