Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I've 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 ??

Posted

Ok, i've 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! :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...