DataTable as DataSource (in Report Designer)

edited 9:21AM in FastReport .NET
Hey,

I've created some reports with the Report Designer in combination with an ASP.NET page (i pass a parameter and the ConnectionString to thereport) => that works fine!

Now, I want to use a DataTable (from ASP.NET) in combination with the Report Designer, but I don't know how to handle this. I can only add DataSources from a Database, but i can't add DataTables.

Has anybody the same problem?
Is this possible to use a DataTable in the Designer?

Thanks,
BG Markus

Comments

  • edited 9:21AM
    just for sharing, i use fastreport in a different scenario, WebAPI.
    Imports System.Net
    Imports System.Net.Http
    Imports System.Net.Http.Headers
    Imports System.Web.Http
    Imports System.Data.SqlClient
    Imports System.Web.Configuration
    
    Namespace API
        Public Class ReportController
            Inherits ApiController
    
            <HttpPost>
            Public Function LoadReport(<FromBody()> ByVal value As integer) As String
                Dim retval As String = String.Empty
                Try
                    Dim mySQLConnString As String = WebConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
                    Dim mySQL As String = String.Empty
                    Dim myFRX As String = String.Empty
    
                    Select Case value
                                Case 0
                                    mySQL = "sp_Inv_Print"
                                    myFRX = "~/App_Data/Print_Inv.frx"
                                Case 1
                                    mySQL = "sp_DP_Print"
                                    myFRX = "~/App_Data/Print_Beli_DP.frx"
                                Case Else
                                    Throw New Exception("Unauthorized.")
                    End Select
                    
                    Using cnn As New SqlConnection(mySQLConnString)
                        cnn.Open()
    
                        Using cmd As New SqlCommand
                            cmd.Connection = cnn
                            cmd.CommandType = CommandType.StoredProcedure
                            cmd.CommandText = mySQL
                            Using wr As New FastReport.Web.WebReport
                                wr.Width = System.Web.UI.WebControls.Unit.Percentage(100)
                                wr.Height = System.Web.UI.WebControls.Unit.Percentage(100)
                                wr.ShowExports = False
                                wr.ShowRefreshButton = False
                                wr.Zoom = 1.3
                                wr.Report.Load(HttpContext.Current.Server.MapPath(myFRX))
    
                                Using dr As SqlDataReader = cmd.ExecuteReader
                                    Using dt As New DataTable
                                        dt.Load(dr)
                                        dt.TableName = "MainReport"
                                        If dt.Rows.Count = 0 Then Throw New Exception("Record not found.")
                                        wr.Report.RegisterData(dt, dt.TableName)
                                    End Using
                                End Using
    
                                retval = wr.GetHtml.ToHtmlString
                            End Using
                        End Using
                    End Using
    
                Catch ex As Exception
                    retval = "<h3>" + ex.Message + "</h3>"
                End Try
                Return retval
            End Function
    
        End Class
    
    End Namespace
    
    
    [b]code for webpage:[/b]
    
            $.ajax({
                type: "POST",
                url: "/api/report/loadreport",
                data: JSON.stringify(1),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#fastreport").html(data);
                }
            });
            <div id="fastreport"></div>
    

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.