Another question about Crystal Reports

Puiu

Well-known member
Joined
Oct 6, 2004
Messages
90
Ive decided to create a report based on an sql query...something like this:

Dim SqlConn As New SqlConnection("Data Source=PUIUALEX;User Id=Puiu;password=puiu2108;" & _
"Initial Catalog=ImageLibrary;")


Dim StrSql As String = "select Media.Description, Media.idmedia, count(*) as TotalDownloads from Media, Images, Requests where Media.idmedia=Images.idmedia AND Requests.idmedia=Media.idmedia AND Requests.aproved=T group by Media.Description, Media.idmedia"


Dim objDa As New SqlDataAdapter(StrSql, SqlConn)
Dim objDs As New DataSet

If SqlConn.State <> ConnectionState.Open Then
SqlConn.Open()
End If

objDa.Fill(objDs)

rpt.SetDataSource(objDs)
CrystalReportViewer1.ReportSource = rpt
DataBind()
-----------------------------------------------------------------------
rpt=report document

If I use the code above the report shows blank!

If I use instead rpt.SetDataSource(objDs.Tables(0)) i get the error: Invalid Table Number.

If i try to fill a datagrid instead of a report after the objDa.Fill(objDs) it works very well!

Any clues ??
 
Ok, ive got it :cool:
Let me explain, maybe it will help someone in the future:
After i make the connection to the database instead of selecting a table or multiple tables i select to add a command:

select Media.Description, Media.idmedia, count(*) as TotalDownloads from Media, Images, Requests where Media.idmedia=Images.idmedia AND Requests.idmedia=Media.idmedia AND Requests.aproved=T group by Media.Description, Media.idmedia

This command will generate the columns i need and wich i can drag now on my report
If now i want to alter the information displayed i can simply modify the sqlString
Cheers! :)
 
Back
Top