【问题标题】:Crystal Reports VB.NET--use sql select command and add a datacolumnCrystal Reports VB.NET--使用sql select命令并添加数据列
【发布时间】:2016-04-18 18:56:09
【问题描述】:

我正在使用 VB .NET 和 Visual Studio Crystal Reports 工具。我正在生成一个使用 SQL 查询、填充数据表并根据数据表中的字段值添加数据列的报告。数据表已填充,但不会显示在报表上。我使用 XSD 文件作为包含 SQL 查询字段和数据列字段的报告的数据源。

Dim sqlAdapter As New SqlDataAdapter()
Dim dt As New DataTable
sqlAdapter.SelectCommand = New SqlCommand(SELECT * FROM [database], validConnectionString)
sqlAdapter.Fill(dt)

Dim addedColumn As New DataColumn ("addedColumn", Type.GetType("System.String"))
dt.Columns.Add(addedColumn)

'Logic to fill the column (tested and used without fail throughout other parts of project)

Dim bsv As New CRReportViewer 'class type that works for all other reports
Dim rpt As New CompletedReport 'class type that follow pattern that works elsewhere
bsv.DataContext = Me
rpt.SetDataSource(dt)
bsv.ReportViewer.ViewerCore.ReportSource = rpt
bsv.Show()

如果我插入类似 'MsgBox(dt.Rows(0).Item(" addedColumn)) 的内容,我会得到一个有效值。但是,该值不会出现在报告中。SelectCommand 中的所有内容都没有问题。

【问题讨论】:

  • 你想为报告生成动态字段
  • 它是一个动态字段。但是,我被要求在 sql 端执行此操作。问题是设置一个 cangrow 属性。该字段最多为一个字符,当字段较长时,该字段默认为空。

标签: vb.net crystal-reports


【解决方案1】:

上面的代码确实有效。问题出在 .rpt 文件的字段中。长度和默认提交有问题。

顺便说一句,似乎一旦 dt 包含有效条目——其他所有内容都在 Crystal 报告编辑器和 .rpt 文件中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 2010-10-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多