Sunday, February 19, 2012

Data in dataset, no data in CR?

Hi,
I am using VS.net 2003 with emb. Crystal reports.

I retrieve data from a database using VB.net and populate a dataset. The records in the dataset are OK, but no data is shown in the report. How come? I use the following code:

I created a schema, called DSUrenPerProject.xsd. In the IDE I put 6 tables from a SQLserver-database on it.

Then I created the Crystal report and put some field from different tables on the report.

================ Then I created the next class============

Imports System.Data
Imports System.Data.OleDb
Public Class DataSetConfiguration

Public Shared ReadOnly Property CustomerDataSet() As DataSet
Get
Dim myDataSet As DSUrenPerProject = New DSUrenPerProject
Dim myOleDBConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(DB4D)
Dim myOleDbDataAdapter As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(mSQL, myOleDBConnection)

Try
myOleDbDataAdapter.Fill(myDataSet, "Uren")
Catch ee As Exception
MsgBox(ee.Message)
End Try
Return myDataSet
End Get
End Property
End Class
===========Then I created the next procedure in another form=====
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim m_Year As Integer
Dim m_Month As Integer
Dim m_Day As Integer
m_Year = DatePart(DateInterval.Year, Date.Parse(DTDatum.Text))
m_Month = DatePart(DateInterval.Month, Date.Parse(DTDatum.Text))
m_Day = DatePart(DateInterval.Day, Date.Parse(DTDatum.Text))

Dim m_Str As String
Dim m_Positie As Integer
m_Positie = InStr(cmbProjecten.Text, "-")
m_Str = Mid(cmbProjecten.Text, 1, m_Positie - 1)
Call init_Pr_PrNr(m_Str)
m_ProjectID = CInt(ds.Tables("Projecten").Rows(0).Item("ProjectID"))
Call Close_init()
If RBDag.Checked = True Then
m_Projectnr = Trim(m_Str)
m_Datum = CDate(Format(Date.Parse(DTDatum.Text), "dd/MM/yyyy"))
'Tbv 4DUren
mSQL = "SELECT Medewerkers.Voornaam as MedNaam, Medewerkers.Achternaam, Opdrachtgevers.Naam as OGNaam, "
mSQL = mSQL & "Contactpersonen.Achternaam as CPNaam, Projecten.Projectnummer, Projecten.Projectomschrijving, "
mSQL = mSQL & "CONVERT(char(10),Urenverantwoording.Datum, 120), Urenverantwoording.Uren100, Urenverantwoording.Uren150, "
mSQL = mSQL & "Urenverantwoording.Ziek, Urenverantwoording.Verlof, Urenverantwoording.Diverse "
mSQL = mSQL & "from Medewerkers, Opdrachtgevers, Contactpersonen, Urenverantwoording, Projecten "
mSQL = mSQL & "WHERE Urenverantwoording.ProjID= " & m_ProjectID & " AND DATEPART(YEAR, Urenverantwoording.Datum) =" & m_Year & " AND DATEPART(MONTH, Urenverantwoording.Datum) = " & m_Month & " AND DATEPART(DAY, Urenverantwoording.Datum) = " & m_Day
mSQL = mSQL & " AND Urenverantwoording.MedID = Medewerkers.MedewerkerID "
mSQL = mSQL & "AND Urenverantwoording.OGID = Opdrachtgevers.OpdrachtgeverID "
mSQL = mSQL & "AND Urenverantwoording.CPID = Contactpersonen.ContactpersoonID "
mSQL = mSQL & "AND Urenverantwoording.ProjID = Projecten.ProjectID "
mSQL = mSQL & "ORDER BY Urenverantwoording.Datum"

End If
frmPrint.ShowDialog()
End Sub
=================at the end I created the next class=========

Imports System.Data
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class frmPrintForm
Inherits System.Windows.Forms.Form
Private customerReport As ReportDocument
Dim myDataSet As DataSet

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
'ConfigureCrystalReports()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents myCrystalReportViewer As CrystalDecisions.Windows.Forms.CrystalReportViewer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.myCrystalReportViewer = New CrystalDecisions.Windows.Forms.CrystalReportViewer
Me.SuspendLayout()
'
'myCrystalReportViewer
'
Me.myCrystalReportViewer.ActiveViewIndex = -1
Me.myCrystalReportViewer.Dock = System.Windows.Forms.DockStyle.Fill
Me.myCrystalReportViewer.Location = New System.Drawing.Point(0, 0)
Me.myCrystalReportViewer.Name = "myCrystalReportViewer"
Me.myCrystalReportViewer.ReportSource = Nothing
Me.myCrystalReportViewer.Size = New System.Drawing.Size(560, 421)
Me.myCrystalReportViewer.TabIndex = 0
'
'frmPrintForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(560, 421)
Me.Controls.Add(Me.myCrystalReportViewer)
Me.Name = "frmPrintForm"
Me.Text = "Printen van..."
Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
Me.ResumeLayout(False)

End Sub

#End Region
Private Sub ConfigureCrystalReports()
customerReport = New ReportDocument
Dim reportPath As String = ""
'reportPath = Application.StartupPath.Substring(0, Len(Application.StartupPath) - 3) & "Test.rpt"

reportPath = Application.StartupPath.Substring(0, Len(Application.StartupPath) - 3) & "CR_UrenPerProject.rpt"
customerReport.Load(reportPath)
Dim myDataSet As DataSet = DataSetConfiguration.CustomerDataSet
customerReport.SetDataSource(myDataSet)
myCrystalReportViewer.ReportSource = customerReport

End Sub

Private Sub frmPrintForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
ConfigureCrystalReports()
End Sub
End Class
=============================================

Thank you for your patience. Can someone help me ?

regards, Ger.Open the report and do very database

No comments:

Post a Comment