How to Show Data from 2 Tables on Crystal Report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rizwan6feb
    New Member
    • Jul 2007
    • 108

    How to Show Data from 2 Tables on Crystal Report

    I am developing a database application in Visual Studion 2008 (VB.Net) . I want to create a stock report which receives data from 2 different tables i.e Products and Stock. I have designed the report but it shows a blank report (only headings, but no data)
    I have used the following code to populate report
    Code:
                Dim r As New rptStock
                Dim ds As New DataSet("DataSet1")
    
                Dim da1 As New SqlCeDataAdapter("Select * from Products", db.getConnection)
                Dim da2 As New SqlCeDataAdapter("Select * from Stock", db.getConnection)
    
                Dim dt1 As New DataTable("Products")
                Dim dt2 As New DataTable("Stock")
                da1.Fill(dt1)
                da2.Fill(dt2)
    
                ds.Tables.Add(dt1)
                ds.Tables.Add(dt2)
                Dim dr As New DataRelation("pk1", dt1.Columns("Code"), dt2.Columns("ProductId"))
                ds.Relations.Add(dr)
    
                r.SetDataSource(ds)
                v1.ReportSource = r
                v1.Show()
    v1 is an instance of crystal report viewer
  • rizwan6feb
    New Member
    • Jul 2007
    • 108

    #2
    I am still looking for help

    Comment

    • NitinSawant
      Contributor
      • Oct 2007
      • 271

      #3
      create a stored procedure and call the stored procedure that returns datatable

      cheers,
      Nitin

      Comment

      • maxamis4
        Recognized Expert Contributor
        • Jan 2007
        • 295

        #4
        In this statement your query needs to be defined better. So the question is do you want specific fields that are relational or are you looking to view both tables in one report. If you are looking for relational values than create your query to reflect the proper joins. If you want to display both tables your best option is to create a union query which you can declare in the statement below. However we need more details on your tables. Starting with their relationship and details on foreign keys and primary keys. If they are not relational we need to understand their purpose.

        dim da1 As New SqlCeDataAdapte r

        Comment

        Working...