breaknrun12
MIS
I'm trying to add a crystal report to my application that uses a dataset with two tables. how do I fill the dataset with the data from the two tables, create the relationship between the two tables, and bind the report to the dataset? Here's the code I got working for the report when it only contained data from one table. What do I need to do add a second table so I can join the tables and display fields from both table on the report?
Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rpt As New CrystalReport1()
Dim myConnection As SqlConnection
Dim myCommand As New SqlCommand
Dim myDA As New SqlDataAdapter
Dim myDS As New DataSet1
Try
myConnection = New SqlConnection("Data Source=LTRSTATEDB;Initial Catalog=Northwind;User ID=sa;Password=LTRAdmin")
myCommand.Connection = myConnection
myCommand.CommandText = ("SELECT * FROM Customers")
myCommand.CommandType = CommandType.Text
myDA.SelectCommand = myCommand
myDA.Fill(myDS, "Customers")
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
Catch ex As Exception
End Try
End Sub