FlexReport and ADO.Net

Posted by: ahmdsalh on 21 December 2017, 9:09 pm EST

    • Post Options:
    • Link

    Posted 21 December 2017, 9:09 pm EST

    Hi,

    I’m new to using FlexReport with visual basic. So simply i want to get a dataset using ADO.NET (the database is SQL server 2012) and then render that set to a report. (All using code)

    I’ve tried the tutorial in the documentation but each time i try to load the report i got an error (in the status bar of the report viewer) regarding the data provider is not specified.

    What is the data provider in this case and what should i do to have simple reports for data coming from datasets or from c1flexgrid.

    Thanks for your support.

  • Posted 22 December 2017, 3:01 am EST

    Hello,

    To first get the data from an SQL Server to DataSet and then use this DataSet to bind a report, you can use the below mentioned code snippet:

    
    Dim adapter As SqlDataAdapter
      Dim _dataSet As New DataSet
      Dim con As SqlConnection
      Dim dt As New DataTable
      Dim str As String = "Data Source = DatasourceName; Initial Catalog = DBName; User ID = ID; Password = pwd"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          C1FlexReport1.Load("../../Cars_SQLServer.flxr", "Products")
          _dataSet.Tables.Add(dt)
          Using con = New SqlConnection()
              con.ConnectionString = str
              con.Open()
              Using adapter = New SqlDataAdapter("Select * from products", con)
                  adapter.Fill(dt)
              End Using
          End Using
          C1FlexReport1.DataSource.Recordset = dt
          C1FlexViewer1.DocumentSource = C1FlexReport1
      End Sub
    
    

    In order to bind the report to the database, use the below mentioned code snippet:

    
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            C1FlexReport1.Load("../../Cars_SQLServer.flxr", "Products")
           
      	C1FlexReport1.DataSource.ConnectionString = "Provider = [b]SQLOLEDB[/b];Persist Security Info=True;User ID=ID;Password=pwd;Initial Catalog=DBName;Data Source=DataSourceName"
            C1FlexReport1.DataSource.RecordSource = "Products"   'Table's name
    
            C1FlexViewer1.DocumentSource = C1FlexReport1
        End Sub
    
    

    The data provider in this case is SQLOLEDB.

    Let us know if you need further assistance.

    Best Regards,

    Esha

  • Posted 22 December 2017, 4:52 am EST

    Thank you so much. The error has gone. But the data didn’t show (the page is blank) may because i didn’t load a report template first.

    Now i have 2 other questions:

    1- is it necessarily to load a pre-designed report template (can i do this through code)? Is it possible that the report is automatically generated the same way the flexgrid is being populated with data?

    2- How can i pass the data from a filtered flexgrid to a flexreport.

    Thanks again for your great support.

  • Posted 23 December 2017, 7:41 am EST

    Would you please assist me in the questions above?

    "

    1- is it necessarily to load a pre-designed report template (can i do this through code)? Is it possible that the report is automatically generated the same way the flexgrid is being populated with data?

    2- How can i pass the data from a filtered flexgrid to a flexreport.

    Thanks again for your great support. "

  • Posted 26 December 2017, 3:13 am EST

    Hello,

    The blank page may be coming because of the same reason that you mentioned. You need to load a report and you would be good to go.

    Now, answering the two questions:

    1. It is not necessary to load a pre-designed report template. You can create one on your own.

      Refer the attached sample showing a small demo of how a report can be created at runtime (“FlexReportByCode.zip”).

      FlexGrid is a grid control with a default tabular layout. FlexReport may contain various controls and the tabular layout like that of a grid can be made in it using shapes and TextFields. However, these are not automatically generated. One must add controls to the report to see how they are represented in it, once the fields are data bound.

    2. You can pass data from a FlexGrid to a FlexReport by creating an image of the grid (filtered) using the CreateImage method and then using the same image in the ImageField of the FlexReport (“FlexGridInFlexReport.zip”)

    Best Regards,

    Esha

    FlexReportByCode.zip

    FlexGridInFlexReport.zip

Need extra support?

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

Learn More

Forum Channels