如何设置数据源的子报表水晶报表使用vb.net? [英] How to set data source of sub-reports crystal report using vb.net?
问题描述
我是新编程水晶报告,所以请帮助我。我有主报告及其分报告。我知道已经如何设置主报表的数据源,问题是在我的子报表。这里是我为我的主要报告:
尝试
pre>
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是一个datagridview
虽然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)
以
结尾对于每个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)
结束尝试
这是我如何生成数据并将其设置为Crystal报表,现在的问题是在子报表中我不知道如何设置数据源,我试过重复并设置它到下一个表(datagridview)和创建另一个数据表,但它显示空..我尝试
rptDoc.OpenSubreport(0).SetDataSource(dtable2)
希望任何人了解我的问题。
解决方案可能会有点简单,如果你尝试这样
RptDocument.Subreports [0] .SetDataSource(YourDataSource);
I am new in programming crystal Report, so please help me. i have main report with sub-report on it. i know already how to set data source of main report, the problem is in my sub-report. here's how i did for my main report:
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
that's how i generated data and set it to the Crystal report, now the problem is in sub-report i don't know how to set data source, i tried to repeat that and set it to the next table (datagridview) and create another datatable but it shows empty.. i tried
rptDoc.OpenSubreport(0).SetDataSource(dtable2)
hope anybody understand my problem.. thanks in advance
解决方案it might be little bit simple if you try like this
RptDocument.Subreports[0].SetDataSource(YourDataSource);
这篇关于如何设置数据源的子报表水晶报表使用vb.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!