Vb.net Crystal report通过分配给报表的特定记录显示表的所有记录

Vb.net Crystal report通过分配给报表的特定记录显示表的所有记录,vb.net,crystal-reports,crystal-reports-2008,Vb.net,Crystal Reports,Crystal Reports 2008,我正在开发一个windows应用程序。我使用的是Crystal Reports,它运行得非常完美。我的问题是,Crystal report没有按照查询返回的记录显示记录 我已经编写了根据用户输入获取记录的查询。但当我将集合绑定到报表时,它会显示数据库中存在的所有记录,而不是集合中的记录 还有一件事,它在添加参数字段之前工作得很好。如果我使用以下代码行: cr.SetDataSource(oBatches) 它的工作状态,只显示集合中的记录,但提示手动输入参数。下面是代码 Private Sub

我正在开发一个windows应用程序。我使用的是Crystal Reports,它运行得非常完美。我的问题是,Crystal report没有按照查询返回的记录显示记录

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

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

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
Private Sub btnLoadBatch_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnLoadBatch。单击
尝试
Me.Cursor=Cursors.WaitCursor
Dim cr作为新的crMonthwiseBatch
Dim oBatches作为新批次
整数形式的月数=dtFrom.Value.Date.Month
Dim StartDateForBatch As Date=新日期时间(dtBatchStartFromMonth.Value.Year,dtBatchStartFromMonth.Value.Month,“1”)
Dim DaysinMonths为整数=System.DateTime.DaysInMonth(dtBatchStartFromMonth.Value.Year,dtBatchStartFromMonth.Value.Month)
Dim EndDateForBatch=StartDateForBatch.ADDDYS(DaysinMonths)

----->LoadByQuery(“CreatedDate>=#“+StartDateForBatch+”#和CreatedDate在分配数据对象(如下面代码中所标记)后,我没有设置报表的数据源

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
Private Sub btnShowCustomer\u Click\u 1(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnShowCustomer。单击
尝试
Me.Cursor=Cursors.WaitCursor
Dim cr作为新rptDatewiseCustomerReport
作为新顾客的暗淡的眼睛
Dim StartDate作为日期时间
Dim EndDate作为日期时间
StartDate=dtFrom.Value.Date.AddDays(-1)
EndDate=dtTO.Value.Date.AddDays(1)

oCustomers.LoadByQuery(“CreatedDate>=#“+StartDate.Date+”#和CreatedDate在分配数据对象(如下代码所示)后,我没有设置报表的数据源

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
Private Sub btnShowCustomer\u Click\u 1(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnShowCustomer。单击
尝试
Me.Cursor=Cursors.WaitCursor
Dim cr作为新rptDatewiseCustomerReport
作为新顾客的暗淡的眼睛
Dim StartDate作为日期时间
Dim EndDate作为日期时间
StartDate=dtFrom.Value.Date.AddDays(-1)
EndDate=dtTO.Value.Date.AddDays(1)
oCustomers.LoadByQuery(“CreatedDate>=#“+StartDate.Date+”和CreatedDate