【发布时间】: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