如何在运行时选择报告? [英] how to choose report at run time ?
问题描述
大家好
i在我的表单中有报表查看器控件和report1.rdlc和report2.rdlc
我有2个按钮
i想按下按钮1
查看报告1
当我按下按钮2
查看报告2
等待帮助
以下代码可能对您有所帮助...
公共 Sub clientid()
Dim sqlQRY As 字符串
Dim reportPath 作为 字符串 = Company_Reckon_Invoice.Report4.rdlc ' 报告查看器路径
Dim sReportDataSource As 新 ReportDataSource
' sqlQRY =select invoiceid,Clientid ,ClientName,Productname,(SUM(TotalAmount)-Sum(Amountpaid))作为BalanceAmount来自收据,其中Clientid =+ TextBox1.Text +GROUP BY invoiceid,Clientid,Clientname,Productname
sqlQRY = SELECT c.invoiceid,c.clientid,c.clientname,c.productname,d.Description,(SUM(c .totalamount)-SUM(c.amountpaid))作为BalanceAmount FROM收据AS c,发票为d,其中d.clientid = c.clientid和d.clientid = + TextBox1.Text + 和c.productname = d.productname和c.invoiceid = d.invoiceid group by c.invoiceid,c.clientid,c.clientname,c .productname,d.De scription
ds = 新 DataSet
clientidd = 新 OleDbDataAdapter (sqlQRY,conn)
clientidd.Fill(ds, 收据)' receipt =数据库tabel名称
ReportViewer1.LocalReport.ReportEmbeddedResource = reportPath
sReportDataSource.Name = DataSet1 ' DataSet1 =报表查看器中的数据源名称
sReportDataSource.Value = ds.Tables( 0 )
< span class =code-keyword> Dim param( 0 ) As ReportParameter
param( 0 )= 新 ReportParameter( bank,TextBox9.Text)
ReportViewer1.LocalReport.SetParameters(param) )
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(sReportDataSource)
Me .ReportViewer1。 RefreshReport()
结束 Sub
这里Company_Reckon_Invoice.Report4.rdlc
Company_Reckon_Invoice =项目名称。
Report4.rdlc = rdlc报告名称。
现在你只需为你的button1或button2调用clientid()。
你想改变tha rdle意味着只需更改报告路径,数据库表名称和数据源名称......
i希望这个答案对你有帮助..
<您的代码中缺少
ReportPath
。 :O
用 Report1 替换你的Button1
代码:
ReportViewer1.LocalReport.ReportPath = My.Application.Info.DirectoryPath.Replace( \ bin \\ \\ _Debug, )& \ Report1rdlc
我 .Table1TableAdapter.Fill( Me .DataDataSet.Table1)
Dim mReportDataSource < span class =code-keyword> As New ReportDataSource
mReportDataSource.Name = DataSet1
mReportDataSource.Value = Me .DataDataSet.Table1
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(mReportDataSource)
Me .ReportViewer1.RefreshReport()
要为 Report2 添加过滤器,请使用以下代码:
ReportViewer1 .Reset()
ReportViewer1.LocalReport.ReportPath = My.Application.Info.DirectoryPath.Replace( \ bin \Debug, )& ; \ Report2rdlc
Dim 地址作为 新 ReportParameter( 地址,TextBox1.Text)
ReportViewer1.LocalReport.SetParameters(地址)
我希望这能帮到您。 :)
非常感谢:)
如果我先按下按钮2然后按下按钮1它工作正常并且有没问题
但如果按下按钮1然后按下按钮2它只适用于按钮1并且在按钮2代码中发现问题
看到问题
http://imageshack.us/a/img571/239/3a7u.png [ ^ ]
http://imageshack.us/a/img571/239/3a7u.png [ ^ ]
等待帮助
解决方案:
只需在 Button2 上添加以下内容即可暂停ReportViewer
befor正在加载其他Repor t。
ReportViewer1.Reset()
有关更多信息,请参阅我更新的答案。 :)
hi all
i have report viewer control in my form and report1.rdlc and report2.rdlc
and i have 2 buttons
i want when i press the button1
view the report1
and when i press the button2
view the report2
Wait for Help
the following code is may be help you...
Public Sub clientid() Dim sqlQRY As String Dim reportPath As String = "Company_Reckon_Invoice.Report4.rdlc" 'report viewer path Dim sReportDataSource As New ReportDataSource ' sqlQRY = "select invoiceid,Clientid,ClientName,Productname,(SUM(TotalAmount)-Sum(Amountpaid)) as BalanceAmount from receipt where Clientid=" + TextBox1.Text + " GROUP BY invoiceid,Clientid,Clientname,Productname " sqlQRY = " SELECT c.invoiceid,c.clientid,c.clientname,c.productname, d.Description,(SUM(c.totalamount)-SUM(c.amountpaid)) as BalanceAmount FROM receipt AS c,invoice as d where d.clientid = c.clientid and d.clientid=" + TextBox1.Text + " and c.productname=d.productname and c.invoiceid=d.invoiceid group by c.invoiceid,c.clientid,c.clientname,c.productname, d.Description" ds = New DataSet clientidd = New OleDbDataAdapter(sqlQRY, conn) clientidd.Fill(ds, "receipt") ' receipt = database tabel name ReportViewer1.LocalReport.ReportEmbeddedResource = reportPath sReportDataSource.Name = "DataSet1" ' DataSet1=datasource name in report viewer sReportDataSource.Value = ds.Tables(0) Dim param(0) As ReportParameter param(0) = New ReportParameter("bank", TextBox9.Text) ReportViewer1.LocalReport.SetParameters(param) ReportViewer1.LocalReport.DataSources.Clear() ReportViewer1.LocalReport.DataSources.Add(sReportDataSource) Me.ReportViewer1.RefreshReport() End Sub
hereCompany_Reckon_Invoice.Report4.rdlc
Company_Reckon_Invoice=Project name.
Report4.rdlc= rdlc report name.
now you just call the clientid() for your button1 or button2.
you want change tha rdle means just change tha report path,database table name and datasource name...
i hope this answer is helping you..
ReportPath
is missing in your code. :O
Replace yourButton1
Code with this for Report1 :
ReportViewer1.LocalReport.ReportPath = My.Application.Info.DirectoryPath.Replace("\bin\Debug", "") & "\Report1.rdlc" Me.Table1TableAdapter.Fill(Me.DataDataSet.Table1) Dim mReportDataSource As New ReportDataSource mReportDataSource.Name = "DataSet1" mReportDataSource.Value = Me.DataDataSet.Table1 ReportViewer1.LocalReport.DataSources.Clear() ReportViewer1.LocalReport.DataSources.Add(mReportDataSource) Me.ReportViewer1.RefreshReport()
To add filter for Report2 use below code :
ReportViewer1.Reset() ReportViewer1.LocalReport.ReportPath = My.Application.Info.DirectoryPath.Replace("\bin\Debug", "") & "\Report2.rdlc" Dim Address As New ReportParameter("Address", TextBox1.Text) ReportViewer1.LocalReport.SetParameters(Address)
I hope this will help you. :)
Thank you very much :)
if i pressed the button2 first then pressed button1 it works good and there is no problem
but if pressed the button1 first then pressed button2 it works for button1 only and there is a problem found in button2 code
see the problem
http://imageshack.us/a/img571/239/3a7u.png[^]
http://imageshack.us/a/img571/239/3a7u.png[^]
wait for help
Solution :
Just add this below line on Button2 to Rest yourReportViewer
befor Loading other Report.
ReportViewer1.Reset()
For more info refer my updated answer. :)
这篇关于如何在运行时选择报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!