2 Replies - 1504 Views - Last Post: 10 December 2012 - 07:30 PM Rate Topic: -----

#1 .net_Apprentice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-October 12

I Can't Populate Report and CrystalReport programmatically...

Posted 05 December 2012 - 08:33 PM

Hi guys:
I am pulling some info from my Table "CARS". Using two DateTimePickers to set the dates and then search in the DataBase the Download_Date column.
The Query result is shown on DataGridViews ok.
Additionally I have created a Report with the ReportViewer but it shows the whole DataBase info, Not my Query because (I think) I have no code to fill the reports and reportviewers with the DataSet content.
I need to display the content of DataSet2 on a Report or a CrystalReport. I do not know how to do it. I Have NO idea of how to start.
Can someone show me the code to prorammatically display DataSet2 on a Report.rdlc And on a Crystal Report too? I would like to know them both. I AM SORRY to bother.
Thanks in advance.
Here is the code I have:
        Imports System.Data
        Imports System.Data.SqlClient
        Imports CrystalDecisions.CrystalReports.Engine
        Imports Microsoft.Reporting.WinForms

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        
        strStartDate = DateTimePicker1.Value.ToString
        strEndDate = DateTimePicker2.Value.ToString

        Dim coneccion As New SqlConnection("Data Source=(local);Initial Catalog=dbPROJECTCARS;Integrated Security=True")
        sqlSentence2 = "SELECT * FROM CARS WHERE Download_Date BETWEEN @strStartDate AND @strEndDate"

        Dim cmd2 As New SqlCommand(sqlSentence2, conection)
        cmd2.Parameters.Add("@strStartDate", SqlDbType.DateTime).Value = strStartDate
        cmd2.Parameters.Add("@strEndDate", SqlDbType.DateTime).Value = strEndDate

        Dim adp2 As SqlDataAdapter = New SqlDataAdapter(cmd2)
        DataSet2 = New DataSet() 
      
        Try
            conection.Open()
            adp2.Fill(DataSet2, "CARS")
            ''''''''''''''''''''''''''''''''''''''''''''
      rptDataSource = New Microsoft.Reporting.WinForms.ReportDataSource("dbPROYECTOCARROSDataSet", ds.Tables("CARROS"))
      Me.ReportViewer1.LocalReport.DataSources.Clear()
      Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
      Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
      Me.ReportViewer1.RefreshReport()
            '''''''''''''''''''''''''''''

        Catch ex As Exception
            MsgBox("OOps! Can't fill DataSet.", MsgBoxStyle.OkOnly)
        Finally
            DataSet2 = Nothing
            adp2 = Nothing
            conection.Close()
            conection.Dispose()
        End Try
End Sub
  


Is This A Good Question/Topic? 0
  • +

Replies To: I Can't Populate Report and CrystalReport programmatically...

#2 .net_Apprentice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-October 12

Re: I Can't Populate Report and CrystalReport programmatically...

Posted 10 December 2012 - 04:33 PM

Hi guys:
Can someone show me how to fill a crystalreport with my CryDataSet? i need to show in the report the content of my dataset.
Thanks in advance.
This is my query:
Dim rpt As New MyCryRep()
Dim strReportPath = Application.StartupPath & "J:\My SQL\ReportCars\ReportCars\MyCryRep.rpt"
Dim coneccion As New SqlConnection("Data Source=(local);Initial Catalog=dbPROYECTOCARROS;Integrated Security=True")
        
        Public strStartDate, strEndDate As String

        crySQLSentence = "SELECT * FROM CARS WHERE Down_Date BETWEEN @strStartDate AND @strEndDate"
        Dim crycmd As New SqlCommand(crySQLSentence, conection)

        crycmd.Parameters.Add("@strStartDate", SqlDbType.DateTime).Value = strStartDate
        crycmd.Parameters.Add("@strEndDate", SqlDbType.DateTime).Value = strEndDate
        
        Dim cryAdp As SqlDataAdapter = New SqlDataAdapter(crycmd)
        Dim rptDataSource As ReportDataSource
        
        CryDataSet = New DataSet()
        coneccion.Open()
        cryAdp.Fill(CryDataSet)

        conection.Close()


Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8910
  • View blog
  • Posts: 33,420
  • Joined: 12-June 08

Re: I Can't Populate Report and CrystalReport programmatically...

Posted 10 December 2012 - 07:30 PM

Please do not create duplicate topics.. merging them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1