我是编程水晶报道的新手,所以请帮助我。我有主要报告和子报告。我知道如何设置主报表的数据源,问题出在我的子报表中。这是我对主要报告的处理方式:
Try
open_con()
Dim a As String
a = "SELECT * FROM students where year_id=1"
Dim reader As SqlDataReader
cmd = New SqlCommand(a, dbcon)
reader = cmd.ExecuteReader
'tblstud is a datagridview
While reader.Read
tblstud.Rows.Add(reader("name"), reader("address"),reader("grade_level"),reader("id_number"))
End While
reader.Close()
cmd.Dispose()
close_con()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim dtable As New DataTable
With dtable
.Columns.Add("name")
.Columns.Add("address")
.Columns.Add("g_lvl")
.Columns.Add("id_num")
End With
For Each tblrow As DataGridViewRow In Me.tblstud.Rows
dtable.Rows.Add(tblrow.Cells("names").Value, tblrow.Cells("addrs").Value, tblrow.Cells("lvl").Value, tblrow.Cells("ids").Value)
Next
Try
Dim rptDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
rptDoc = New stud_rep
rptDoc.SetDataSource(dtable)
CrystalReportViewer1.ReportSource = rptDoc
Catch ex As Exception
MsgBox(ex.Message)
End Try
我是如何生成数据并将其设置为Crystal报表的,现在问题出现在子报表中我不知道如何设置数据源,我试图重复这一点并将其设置为下一个表(datagridview)并创建另一个数据表,但它显示为空..我试过rptDoc.OpenSubreport(0).SetDataSource(dtable2)
希望有人理解我的问题..提前感谢
答案 0 :(得分:0)
RptDocument.Subreports[0].SetDataSource(YourDataSource);