Skip to Content
0

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

Dec 21, 2016 at 02:06 PM

89

avatar image
    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.
10 |10000 characters needed characters left characters exceeded

That fixed it!!! Thanks Don!!!

0
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Don Williams
Jan 03, 2017 at 06:47 PM
1

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

<startup useLegacyV2RuntimeActivationPolicy="true">

Don

Share
10 |10000 characters needed characters left characters exceeded
Dell Stinnett-Christy Dec 22, 2016 at 03:53 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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)
0
Dell Stinnett-Christy Jan 03, 2017 at 03:20 PM
0

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

-Dell

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.
0
Don Williams
Jan 03, 2017 at 05:48 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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?

0
Dell Stinnett-Christy Jan 04, 2017 at 02:13 PM
0

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

-Dell

Share
10 |10000 characters needed characters left characters exceeded