cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos
    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.
Former Member
0 Kudos

That fixed it!!! Thanks Don!!!

Accepted Solutions (1)

Accepted Solutions (1)

Ah, you are missing this from your app.config file:

<startup useLegacyV2RuntimeActivationPolicy="true">

Don

Answers (4)

Answers (4)

DellSC
Active Contributor
0 Kudos

This is a known error. You need to update your app.config file by replacing "<startup>" with "<startup useLegacyV2RuntimeActivationPolicy="true">".

-Dell

0 Kudos

Hi Pat,

Try using .ReadSchema rather than .Auto, not sure what that one does.

CR requires the XML to have the Schema included with the XML file.

Don

Former Member
0 Kudos

I did get a new error... (cut it down to one)...

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.

This looks like it is probably a reference missing. Am I close?

DellSC
Active Contributor
0 Kudos

You have to load the data into the dataset before you assign the dataset as the report source.

-Dell

Former Member
0 Kudos

The Dataset (ds) is loaded 27 lines before it is designated as the report source for the report document (rd) with

rd.SetDataSource(ds)

What am I missing in this?  I create a Dataset, load data into it from xml, and then try to assign it as report source.  You may well be seeing a problem, I am not.
DellSC
Active Contributor
0 Kudos

I don't see that you're every loading any data into the data set before you assign it to the report. "Dim ds As NewDataSet()" just creates a new, empty dataset - there are no tables or data in it for the report to connect to.

-Dell

Former Member
0 Kudos

The next line is as follows which reads an Xml into the dataset. If I stop the code following this line and check, there is table(s) in the ds dataset.

ds.ReadXml(filePath, XmlReadMode.Auto)