Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted

the following code is may be help you...
VB
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



here
Company_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..
 
Share this answer
 
ReportPath is missing in your code. :O
Replace your Button1 Code with this for Report1 :
VB
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 :
VB
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. :)
 
Share this answer
 
v2
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 your ReportViewer befor Loading other Report.
VB
ReportViewer1.Reset()

For more info refer my updated answer. :)
 
Share this answer
 
v2
Comments
Mehdi Gholam 6-Oct-13 3:57am    
Post a comment for further help, don't post solutions.
Manoj K Bhoir 6-Oct-13 8:14am    
Just add this below line on Button2 to Rest your ReportViewer befor Loading other Report.
ReportViewer1.Reset()
Manoj K Bhoir 6-Oct-13 8:18am    
For more info refer my updated answer. :)
should the attach attach a report1.rdlc and report2.rdlc with executable file or can be used from within the program?

i want to use them from within the program

If there is a solution to this problem will be much better

Any way thank you very much
 
Share this answer
 
Comments
Manoj K Bhoir 6-Oct-13 12:03pm    
Post a comment for further help, don't post solutions.
Also don't forget to Rate 5 if my Solution is helpful to you. :)
Hi Karim...
Still you have any problem means, go to this link http://sdrv.ms/16KYQt8[^]
and download the WindowsApplication2 folder, it is your application without error...
 
Share this answer
 
thank you very much :)

thank you all :)
 
Share this answer
 
Comments
Manfred Rudolf Bihy 6-Oct-13 17:39pm    
Solutions provide an answer, for comments please do use the comment feature.
Your actions have been reported.
Please adhere to the rules of this forum.

Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900