怎样在一张数据报表datareport上显示数据库中三张不同表中的所有记录?表与表之间没有关联互相独立,字段也不相同。

解决方案 »

  1.   

    在DataReport_Initialize()中取得其它表的结果集,在报表界面上拖出label,然后label=rescordset.fields("字段名"),字段多就要多拖几个了,只能是这个样子了,不过给你介绍个好报表控件activereport,它实现起来还是比较好的
      

  2.   

    小佛真是好热心啊,也谢谢小丁丁,不过小丁丁的回答我还是不清楚。回答下米兰的问题,是用SQL做的表,是并列关系,互不联系,一个部门一个表。他们之间的任何一张表都没有关联。我是想在一张报表上,显示出这三张完全没有联系的表的记录。
      

  3.   

    使用临时表
    例如: 
    SELECT cust.name,rcvbles.balance,……other columns 
    FROM cust,rcvbles 
    WHERE cust.customer_id = rcvlbes.customer_id 
    AND rcvblls.balance>0 
    AND cust.postcode>“98000” 
    ORDER BY cust.name 
    INTO TEMP cust_with_balance 将数据报表的名称属性改为DR。 添加和你字段个数相同的Report TextBox到报表中的“细节”区。 在窗体Form1中添加一个名为Command1的命令按钮。 将下述代码放在Form1中: Dim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim cmd As New ADODB.Command
    Private Sub Command1_Click()Dim q As IntegerDim intCtrl As IntegerDim x As IntegerDim z As Integerx = 0q = 0z = 0
    With DR.HideSet .DataSource = rs.DataMember = ""With .Sections("Section1").ControlsFor intCtrl = 1 To .CountIf TypeOf .Item(intCtrl) Is RptLabel Then.Item(intCtrl).Caption = rs.Fields(q).Name & " :"q = q + 1End IfIf TypeOf .Item(intCtrl) Is RptTextBox Then.Item(intCtrl).DataMember = "".Item(intCtrl).DataField = rs(z).Namez = z + 1End IfNext intCtrlEnd With.Refresh.ShowEnd WithEnd Sub
    Private Sub Form_Load()
    Command1.Caption = "Show Report"
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _"Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;"
    With cmd.ActiveConnection = cn.CommandType = adCmdText.CommandText = "Select FirstName, Lastname from Employees".ExecuteEnd With
    With rs.ActiveConnection = cn.CursorLocation = adUseClient.Open cmdEnd With
    End Sub 你试试