Opening C1Report in C1Report Viewer

Posted by: deansaccount on 19 September 2017, 10:41 am EST

  • Posted 19 September 2017, 10:41 am EST

    Hi guys,

    I had a winforms report loading just fine using…

    Try
    
            QuoteReport.Load("XXXReportQuoteTemplate.XML", "Header")
            QuoteReport.DataSource.RecordSource = "SELECT DISTINCT tblSmartQuoteHeader.ID,tblSmartQuoteHeader.Customer,tblSmartQuoteHeader.Attention,tblSmartQuoteHeader.CustomerRef,tblSmartQuoteHeader.QuoteVal, tblSmartQuoteHeader.DateRef,tblSmartQuoteHeader.InternalName,tblSmartQuoteHeader.ExternalName,tblSmartQuoteHeader.Ref FROM  tblSmartQuoteHeader WHERE tblSmartQuoteHeader.AstuteRef = '" & txtID.Value & "'"
            ReportPreviewPane.Document = QuoteReport.Document
    
        Catch Ex As Exception
            MsgBox(Ex.Message)
        End Try
    

    This does not work in WPF. How in WPF in code (vb.net) Do I load a report into a report viewer?

    Thanks.

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    You will have to use the following code, which is similar to the one used in winform application. The only difference is in terms of the viewer :

    [vb]Dim C1DocumentViewer1 As New C1DocumentViewer1

    Dim rep As New C1Report

    rep.Load(FileName, ReportName)

    rep.DataSource.RecordSource = query

    C1DocumentViewer1.Document = C1Report1.FixedDocumentSequence[/vb]

    Regards,

    Mohita

  • Posted 19 September 2017, 10:41 am EST

    Thanks.

    Error on this line…

    Dim ReportViewer_SmartQuote As New ReportViewer_SmartQuote

    Type 'ReportViewer_SmartQuote ’ is not defined

  • Posted 19 September 2017, 10:41 am EST

    Image attached…

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    Apologies for incorrect code in my last post. The code should be as follows :

    Dim DocViewer_SmartQuote As New C1DocumentViewer

    Dim rep As New C1Report

    rep.Load(FileName, ReportName)

    rep.DataSource.RecordSource = query

    DocViewer_SmartQuote…Document = rep.FixedDocumentSequence

    Moreover, I also observe error when defining C1Report. You need to add the missing references in the code :

    Imports C1.C1Report

    Regards,

    Mohita

  • Posted 19 September 2017, 10:41 am EST

    Would this load a sub report within the main report?

    I ask because its loading the main report but not the sub report.

    I hadnt My current code is…

    Dim rep As New C1Report

    rep.Load(“\corefs01Common - GlobalITInspectionsReportReportQuoteTemplate.XML”, “Header”)

    rep.DataSource.RecordSource = “SELECT…”

            DocViewer_SmartQuote.Document = rep.FixedDocumentSequence
    

    Thanks,

    Dean.

  • Posted 19 September 2017, 10:41 am EST

    Hello Dean,

    You mentioned that the sub report is not loaded. Would you please clarify if the data in it does not show up or the subreport field is missing entirely. On loading the MainReport, the subreport also gets loaded. One need not explicitly do the same. However, to me it seems that you are have not set the datasource of the subreport in the code. You may do it in the following manner:

    rep.Sections(“Detail”).Fields(subreport).DataSource and

    rep.Sections(“Detail”).Fields(subreport).RecordSoure

    Let us know if you still face any issues. Also, I would request you to share your sample application (along with the report xml and it’s datasource) with us.

    Regards,

    Mohita

  • Posted 19 September 2017, 10:41 am EST

    Hi Mohita,

    Sadly I cannot post the application or data source.

    Please see image attached. Pleasue also note that the ‘Header’ and ‘LinesReport’ are stored in the same location.

    Thanks,

    Dean

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    As far my understanding of the issue goes, after seeing the screen-shot, it seems that the ‘Header’ and ‘LinesReport’ are two reports in the same definition file ie. ReportQuouteTemplate.xml

    Next, the ‘Header’ is the main report and the ‘LinesReport’ is the subreport added in the mainreport’s detail section with FieldName, say, ‘SubRepField’.

    In this case, if you wish to change the subreport’s datasource and recordosurce, you will have to use the following code :

    rep.Sections(“Detail”).Fields(“SubRepField”).Datasource

    rep.Sections(“Detail”).Fields(“SubRepField”).RecordSource

    Hope it solves your problem. Let us know if you still face any problems. Also, I would request you to share your sample application (along with the report xml and it’s datasource) with us. You may replace the actual data with some dummy values and then share the same with us.

    Regards,

    Mohita

  • Posted 19 September 2017, 10:41 am EST

    Yes your assumptions were correct. So based on that…

    Is “SubRepField” the field which links the main report to the sub report.

    Im assuming the RecordSource is the SQL statement?

    ie SELECT DISTINCT WPFtblSmartQuoteLines.LinesID, WPFtblSmartQuoteLines.LinesAstuteRef FROM WPFtblSmartQuoteLines

    Is the Datasource the connection string?

    "\corefs01Common - GlobalITInspectionsReportLinesReport.XML

    Thanks,

    Dean

  • Posted 19 September 2017, 10:41 am EST

    Ok I am now trying with the following code…

    Dim rep As C1Report = New C1Report()

    rep.Load(“\corefs01Common - GlobalITInspectionsReportReportQuoteTemplate.XML”, “Header”)

    ’ set data source for main report

    rep.DataSource.ConnectionString = “Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=OMSystem;Data Source=COREDB01”

    ’ search for field with subreport

    Dim fldSubReport As Field = rep.Fields(“LinesAstuteRef”)

    If Not IsNothing(fldSubReport) Then

    fldSubReport.Subreport.DataSource.ConnectionString = “Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=OMSystem;Data Source=COREDB01”

    End If

    rep.Render()

    It says…field ‘LinesAstuteRef’ cannot be found. But it does exist.

    Thanks,

    Dean

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    You should not face any issue if the ‘LinesAstuteRef’ field is present in the main report. The same can be accessed with the code mentioned by you. Please make sure that the field name mentioned by you is correct and is present in the mainreport.

    Attached is a sample application for your reference implementing the same. Next, it would be helpful if you can share a sample with us replicating the issue. May be not your original sample but a one with dummy values created on the same lines and the one that replicates the issue.

    Note : the datasource is C1Nwind.

    Regards,

    Mohita

    2012/08/SubReport-ConnectionStringAtRunTime.zip

  • Posted 19 September 2017, 10:41 am EST

    Ah this may be the problem…

    The reports are linked by AstuteRef in the main report and LinesAstuteRef in the sub report

    Thanks,

    Dean

  • Posted 19 September 2017, 10:41 am EST

    Hi, thanks for the reply, Ok so this is now my code…

    Dim rep, repsub As New C1Report

    rep.Load(“\corefs01Common - GlobalITSmartQuote ReportingReportQuoteTemplate.XML”, “Header”)

            Dim fldSubReport As Field = rep.Fields("AstuteRef")
            If Not IsNothing(fldSubReport) Then
                fldSubReport.Subreport.DataSource.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=OMSystem;Data Source=COREDB01"
            End If
            rep.Render()
    
            DocViewer_SmartQuote.Document = rep.FixedDocumentSequence
    

    Object reference not set to an instance of an object?

    Thanks,

    Dean

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    Did the sample sent by me run fine at your end? If yes, then the code used by you is correct and you should not give any error.

    I am not sure why you are facing any issues and hence can not comment on it. I would request you to share your sample application (with dummy data) with us. It would help us in narrowing down the issue and providing you with a n appropriate solution.

    Regards,

    Mohita

  • Posted 19 September 2017, 10:41 am EST

    +1 on this problem.

    I have a number of reports defined in my xml, but only one of them contains subreports.

    I have used the code noted to set the datasource of the subreports. It seems that everything is in place, however I also get the same exception on the same line. “Object reference not set to an instance of an object” and instruction to check my connection source etc. In my case, I’m passing in all of the report data as an ObservableCollection within a ReportDataSource;

        report.Fields["leftReport"].Subreport.DataSource.Recordset = new ReportDataSource(myDataOC);
    

    It seems as though “FixedDocumentSequence” doesn’t work with subreports?

  • Posted 19 September 2017, 10:41 am EST

    Hello,

    Are you facing the issues only with the report having subreports?

    Or is it replicable with any report whose datasource is set to ObservableCollection?

    Could you please share a sample application with us replicating the issues? It would help us in narrowing down the issue and providing you with better assistance.

    Thanks and Regards,

    Mohita

  • Posted 1 February 2018, 8:18 am EST

    I have one question regarding paper size. In report i set layout - paper size to A3 and load report

    Declaration

    
    Public WithEvents rep As New C1.C1Report.C1Report()
    
    

    on click

    
    
     rep.Load(fileFullPath, reportName)
      c1DocumentViewer.Document = rep.FixedDocumentSequence
    
    
    

    I have problem that size is always as A4, what should i do to view report on A3 size ??

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels