Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
In my report i want to display the values from two different tables, how can i set the datasource using coding to report at runtime

For example i give the following but it is not working

it is display all the fields in second table i want to display one table at a time how to do it

VB
Dim rrview As New reportviewer
        Dim ProDset1 As New DataSet
        Dim sqlda As New SqlDataAdapter("select * from PL where fromdate='" & Format(fromdate.Value, "MM-dd-yyyy") & "' and todate='" & Format(todate.Value, "MM-dd-yyyy") & "'", con)
        Dim sqlda1 As New SqlDataAdapter("select * from Expenses where Date>= '" & Format(fromdate.Value, "MM-dd-yyyy") & "' and Date<= '" & Format(todate.Value, "MM-dd-yyyy") & "'", con)
        sqlda.Fill(ProDset1, "T1")
        sqlda1.Fill(ProDset1, "T2")
        Dim RptProstmt As New Crystal10
        RptProstmt.SetDataSource(ProDset1)

        rrview.viewer1.ReportSource = RptProstmt
        rrview.viewer1.DisplayGroupTree = False
        rrview.MdiParent = MyBase.MdiParent
        rrview.Show()
Posted

1 solution

Just assign the Table instead of DataSet.
VB
RptProstmt.SetDataSource(ProDset1.Tables(0))


EDIT

VB.NET Crystal Reports from multiple tables[^]
 
Share this answer
 
v2
Comments
devausha 30-Dec-11 7:13am    
But it has get the records from first table. it didn't display the records from another table
thatraja 30-Dec-11 7:15am    
May be something wrong with data. Check the data in preview time. Check updated answer
bluesathish 31-Dec-11 1:05am    
Hi devausha, Instead of assigning dataset to the reportdatasource, just try to do by adding reportdatasource.add() method. Which means, write the for loop as initialize one loop variable to 1 untill the dataset's tables count. And by calling the add() method you can assign the datasource one by one. Hope this will be helpful.
devausha 1-Jan-12 23:46pm    
Hai thank you very much for your reply
but i am not clearly for your comment
where i have to give reportdatasource.add() method, i give this line error will occured please explain how to do it

Thank you very much
thatraja 2-Jan-12 4:31am    
Did you try that?(RptProstmt.SetDataSource(ProDset1.Tables(0)))

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