3 Replies - 3285 Views - Last Post: 01 October 2013 - 04:17 AM Rate Topic: -----

#1 TheOnlyErs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-October 13

How to dsplay data coming from two tables on one crystal report?

Posted 01 October 2013 - 02:49 AM

Good day to all.

I am new here. I decided to join this forum to get some help with a project I'm working on using VB.net

Here's my problem.

I'm trying to display two tables on one crystal report using this code below.

Dim MyCommand As New SqlCommand()
Dim DataAdapter1, DataAdapter2, DataAdapter3 As New SqlDataAdapter
Dim myDS As New DataSet1()

Dim rpt As New StudentWithTheMostViolationsReport()

DataAdapter1 = New SqlDataAdapter("SELECT vd.StudID, info.studLname, info.studFname, info.studMname from tblViolationDetails As vd FULL JOIN tblStudentInfo as info on vd.ViolationDetailsID = info.StudID", con)
           

DataAdapter1.Fill(myDS, "tblViolationDetails")
DataAdapter1.Fill(myDS, "tblStudentInfo")

rpt.SetDataSource(myDS)
frmReportViewer.ReportViewer.ReportSource = rpt

frmReportViewer.ShowDialog()


After running the program, the report looks like this:

StudID studLname studFname studMname

1 Doofenshimrtz Heinz Evil
Flynn Candace Gertrude

2 Doofenshimrtz Heinz Evil
Flynn Candace Gertrude

If you take a look at it. The information being displayed on the report are being repeated. Moreover, the student ID 2 should be along side "Flynn Candace Gertrude" and not along side "Doofenshimrtz Heinz Evil".

What I want to do is to display the StudentID which comes from one table and the full name of the student coming from another table.

I thought of changing the kind of "join" I'm using. I tried left join and I also tried inner join but changing the "join" didn't do the trick.

A helpful advice is greatly appreciated. Thank you. :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to dsplay data coming from two tables on one crystal report?

#2 jimzcoder   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 351
  • Joined: 14-November 12

Re: How to dsplay data coming from two tables on one crystal report?

Posted 01 October 2013 - 03:27 AM

check the way you fill in your dataset. since you used table join the result will be displayed or grouped as 1 table.
Was This Post Helpful? 0
  • +
  • -

#3 TheOnlyErs   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-October 13

Re: How to dsplay data coming from two tables on one crystal report?

Posted 01 October 2013 - 03:39 AM

View Postjimzcoder, on 01 October 2013 - 03:27 AM, said:

check the way you fill in your dataset. since you used table join the result will be displayed or grouped as 1 table.


Thanks for the response jimzcoder. I see what you mean there.

I did try getting rid of one of the "DataAdapater1" which has the tblStudentInfo. When I did, the report only displayed the student id and didn't display the names. When I got rid of the other data adapter, the one with the tblViolationDetails, nothing was displayed on the report.

The question now is, what is the right way of filling the dataset that will show values that were joined by a query.
Was This Post Helpful? 0
  • +
  • -

#4 jimzcoder   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 351
  • Joined: 14-November 12

Re: How to dsplay data coming from two tables on one crystal report?

Posted 01 October 2013 - 04:17 AM

just use
DataAdapter1.Fill(myDS)
rpt.DataSource(myDS.Tables(0))
'instead of using/specifying the source table
'and see what happens then


This post has been edited by jimzcoder: 01 October 2013 - 04:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1