Skip to Content
avatar image
Former Member

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

    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.
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Jan 03, 2017 at 06:47 PM

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

    <startup useLegacyV2RuntimeActivationPolicy="true">

    Don

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 22, 2016 at 03:53 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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)
  • Jan 03, 2017 at 03:20 PM

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

    -Dell

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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?

  • Jan 04, 2017 at 02:13 PM

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

    -Dell

    Add comment
    10|10000 characters needed characters exceeded