【问题标题】:My crystal cannot populate anything from two tables我的水晶无法填充两张桌子上的任何东西
【发布时间】:2020-11-24 00:54:49
【问题描述】:

显示未付发票的日常报告的功能

Public Sub DayToDayUnpaidInvoice()
    Try
        connection.Open()
        CrystalReportViewer1.Refresh()
        Dim sql As String = "SELECT tblclientinfo.Client_ID, tblclientinfo.C_name, tblclientinfo.C_surname, tblinv_info.inv_Num , tblinv_info.Inv_date  
                            FROM tblclientinfo,tblinv_info 
                            WHERE tblclientinfo.Client_ID = tblinv_info.Client_ID AND inv_paid = 'N' OR inv_paid = '' 
                            ORDER BY inv_date ASC;"
        cmd = New MySqlCommand(sql, connection)
        da = New MySqlDataAdapter()
        da.SelectCommand = cmd
        ds = New DataSet
        da.Fill(ds, "tblclientinfo")
        Dim report As New DayToDayUnpaid
        report.SetDataSource(ds)
        CrystalReportViewer1.ReportSource = report
        CrystalReportViewer1.Refresh()
        cmd.Dispose()
        da.Dispose()
        ds.Dispose()
        connection.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
        connection.Close()
    End Try
End Sub

【问题讨论】:

  • 那么问题出在哪里?错误?或者只是没有数据?如果直接通过查询工具查询数据库,查询是否返回预期数据?
  • 没有数据,只有标题,我使用相同的代码从一个表中查询一些信息,幸运的是它工作正常,但是当有两个表时我很挣扎,谢谢。
  • 当我使用其他工具时,查询给了我预期的结果。

标签: mysql vb.net crystal-reports


【解决方案1】:

改变这个:

report.SetDataSource(ds)

到这里

report.SetDataSource(ds.Tables(0))

【讨论】:

  • 谢谢,我会这样做,此外,如果我可以问,因为我从两个表中查询,这里的这行代码可以这样:da.Fill(ds, "tblclientinfo") 或者我必须包含两个表名
  • 没关系。您的查询将只返回一个表
  • 我明白,但我的查询是从两个表中请求数据,因此我担心这个 da。填充功能,请指教。
  • 可以通过Console.WriteLine(ds.Tables.Count)看到你的查询返回了多少表
  • 我能否改写我的问题,如何使用提供的代码从两个表中检索信息,或者更确切地说是我在哪里丢失了它?
猜你喜欢
  • 2023-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-28
  • 2021-02-07
  • 2012-09-06
  • 1970-01-01
相关资源
最近更新 更多