【问题标题】:Crystal report shows all records of table though specific records assigned to report水晶报表通过分配给报表的特定记录显示表的所有记录
【发布时间】:2015-10-13 13:25:04
【问题描述】:

我正在开发一个 Windows 应用程序。我正在使用 Crystal Reports,它运行良好。我的问题是,水晶报表没有根据查询返回的记录显示记录。

我已经根据用户输入编写了获取记录的查询。但是当我将集合绑定到报告时,它会显示数据库中存在的所有记录,而不是我在集合中的记录。

还有一件事,在添加参数字段之前它工作得很好。如果我使用下面的代码行:

cr.SetDataSource(oBatches)

它的工作,显示集合中的唯一记录,但提示手动输入参数。下面是代码。

Private Sub btnLoadBatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadBatch.Click
    Try
        Me.Cursor = Cursors.WaitCursor
        Dim cr As New crMonthwiseBatch
        Dim oBatches As New Batches
        Dim Month As Integer = dtFrom.Value.Date.Month
        Dim StartDateForBatch As Date = New DateTime(dtBatchStartFromMonth.Value.Year, dtBatchStartFromMonth.Value.Month, "1")
        Dim DaysinMonths As Integer = System.DateTime.DaysInMonth(dtBatchStartFromMonth.Value.Year, dtBatchStartFromMonth.Value.Month)
        Dim EndDateForBatch = StartDateForBatch.AddDays(DaysinMonths)

        ----->      oBatches.LoadByQuery("CreatedDate >= #" + StartDateForBatch + "# and CreatedDate <= #" + EndDateForBatch + "#")

        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As New ParameterValues
        Dim crParameterDiscreteValue As New ParameterDiscreteValue

        crParameterDiscreteValue.Value = "Batch List of Month " + MonthName(dtBatchStartFromMonth.Value.Month) + " " + dtBatchStartFromMonth.Value.Year.ToString
        crParameterFieldDefinitions = cr.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item("MonthName")
        crParameterValues = crParameterFieldDefinition.CurrentValues
        crParameterValues.Clear()
        crParameterValues.Add(crParameterDiscreteValue)
        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
        CrystalReportViewerMonthwiseBatch.ReportSource = cr
        CrystalReportViewerMonthwiseBatch.Refresh()
        Me.Cursor = Cursors.Arrow
    Catch ex As Exception
        Me.Cursor = Cursors.Arrow
        MessageBox.Show("Error :- " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

【问题讨论】:

    标签: vb.net crystal-reports crystal-reports-2008


    【解决方案1】:

    在分配数据对象(如下面代码中标记)后,我没有设置报表的数据源。

    Private Sub btnShowCustomer_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowCustomer.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Dim cr As New rptDatewiseCustomerReport
            Dim oCustomers As New Customers
            Dim StartDate As DateTime
            Dim EndDate As DateTime
            StartDate = dtFrom.Value.Date.AddDays(-1)
            EndDate = dtTO.Value.Date.AddDays(1)
            oCustomers.LoadByQuery("CreatedDate >= #" + StartDate.Date + "# and CreatedDate <= #" + EndDate.Date + "#")
    
            'Added Line below---->        
            cr.SetDataSource(oCustomers)
    
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As New ParameterValues
            Dim crParameterDiscreteValue As New ParameterDiscreteValue
            Dim DatetimeTest As String = dtFrom.Value.Date.ToString("dd-MMM-yyyy").ToString + " To " + dtTO.Value.Date.ToString("dd-MMM-yyyy").ToString()
    
            crParameterDiscreteValue.Value = DatetimeTest
            crParameterFieldDefinitions = cr.DataDefinition.ParameterFields
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("paraFromDate")
            crParameterValues = crParameterFieldDefinition.CurrentValues
            crParameterValues.Clear()
            crParameterValues.Add(crParameterDiscreteValue)
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
            CrystalReportViewer2.ReportSource = cr
            CrystalReportViewer2.Refresh()
            Me.Cursor = Cursors.Arrow
        Catch ex As Exception
            Me.Cursor = Cursors.Arrow
            MessageBox.Show("Error :- " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      相关资源
      最近更新 更多