I have what you need from an old application, it is visual basic, but it gives you the logic of what you should do:
Dim parametro As New ParameterValues
Dim tipo As New ParameterDiscreteValue
Dim reporte As New rpt_puestos
Dim con_base As New SqlClient.SqlConnection
Dim adp_div As New SqlClient.SqlDataAdapter
Dim puesto As New DataTable
Dim sqlcadena As String
con_base.ConnectionString = Application("cadena").ToString
sqlcadena = "select * from tabla"
adp_div = New SqlClient.SqlDataAdapter(sqlcadena, con_base)
puesto = New DataTable
adp_div.Fill(puesto)
reporte.SetDataSource(puesto)
puesto = New DataTable
adp_div.Fill(puesto)
parametro.Add(tipo)
tipo.Value = "TITULO REPORTE"
puesto.Dispose()
con_base.Dispose()
adp_div.Dispose()
reporte.DataDefinition.ParameterFields("titulo").ApplyCurrentValues(parametro)
reporte.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, tipo.Value.ToString.Replace(" ", "_"))
Response.[End]()
reporte.Dispose()
What you need is to give the data source of the report the table that you have already obtained from the query, if the report has other parameters such as title or something else, this is the example of how to pass them and finally the report is exported in pdf format, but this can be changed according to what is needed.
In summary:
You must add the crystal reports references
You must create the report with the crystal reports designer and save it in some folder of the application
If the report has parameters you should add them in the code, if not with the only data source is enough
add the table to the datasource of the report
Export the report
(The code in c # is very similar)