Entity framework

How can we use IEnumerable in datasource of fastreport ( ASP.NET )??

Comments

  • edited 8:25AM
    read http://www.codeproject.com/Articles/739164...l-for-Beginners

    pull data from entity object, convert to list<T>, please note that List<T> implements the IEnumerable<T> interface

    for fastreport, there is an example in c# => DataFromBusinessObject
  • Ok. I tested this solution but fastreport shows all records!!!
    I do not khow how can i use WebReport1.Report.RegisterData(??, ??)
    Could you write some code for passing IEnumerable parameter??
  • edited 8:25AM
    Record filtering should be done in query, not fastreport.

    Sorry, I don't have exact example, never use entity framework, but you may get the idea.
    My scenario is using AJAX to call webAPI.

    In businessobject class :
        Public Class myReportCOA
            Public Property Acc3Code As String
            Public Property Acc3Name As String
            Public Property Acc0Urut As Integer
            Public Property Acc1Urut As Integer
            Public Property Acc1Name As String
            Public Property Acc2Urut As Integer
            Public Property Acc2Name As String
        End Class
    

    In WebAPI controller :
        <HttpPost>
        Public Function FRCOALoad() As String
            Dim retval As String = String.Empty
            Try
                Dim mySQLConnString As String = WebConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
                Using cnn As New OleDbConnection(mySQLConnString)
                    cnn.Open()
    
                    Using cmd As New OleDbCommand
                        cmd.Connection = cnn
                        cmd.CommandType = CommandType.Text
                        cmd.CommandText = "SELECT * FROM qryRptListCOA"
    
                        Using wr1 As New FastReport.Web.WebReport
                            wr1.Width = System.Web.UI.WebControls.Unit.Percentage(100)
                            wr1.Height = System.Web.UI.WebControls.Unit.Percentage(100)
                            wr1.ShowExports = False
                            wr1.ShowRefreshButton = False
    
                            Using dr As OleDbDataReader = cmd.ExecuteReader()
                                Dim myData As New List(Of myReportCOA)
                                While dr.Read
                                    myData.Add(New myReportCOA With {.Acc3Code = dr.GetString(5), .Acc3Name = dr.GetString(6), .Acc0Urut = dr.GetInt32(0), .Acc1Urut = dr.GetInt32(1), .Acc1Name = dr.GetString(2), .Acc2Urut = dr.GetInt32(3), .Acc2Name = dr.GetString(4)})
                                End While
    
                                If myData.Count > 0 Then
                                    wr1.Report.Load(HttpContext.Current.Server.MapPath("~/App_Data/rptCOA.frx"))
                                    wr1.Report.RegisterData(myData, "MainReport")
                                Else
                                    Throw New Exception("Record not found.")
                                End If
                            End Using
    
                            retval = wr1.GetHtml.ToHtmlString
                        End Using
                    End Using
                End Using
    
            Catch ex As Exception
                retval = "<h3>" + ex.Message + "</h3>"
            End Try
            Return retval
        End Function
    

    In HTML View :
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                url: "/api/webgl/FRCOALoad",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#fastreport").html(data);
                },
                error: function (xhr, status, error) {
                    alert(error);
                }
            });
        });
    </script>
    <div id="fastreport"></div>
    

    In FRX (fastreport) file :
      <Dictionary>
        <BusinessObjectDataSource Name="MainReport" ReferenceName="MainReport" DataType="System.Int32" Enabled="true">
          <Column Name="Acc3Code" DataType="System.String"/>
          <Column Name="Acc3Name" DataType="System.String"/>
          <Column Name="Acc0Urut" DataType="System.Int32"/>
          <Column Name="Acc1Urut" DataType="System.Int32"/>
          <Column Name="Acc1Name" DataType="System.String"/>
          <Column Name="Acc2Urut" DataType="System.Int32"/>
          <Column Name="Acc2Name" DataType="System.String"/>
        </BusinessObjectDataSource>
      </Dictionary>
    

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.