Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys

I want to print a database table with Crystal Report.
In a form I have a DateTimePicker(dtpDate) and a button with this code

VB
 Private Sub btnDayPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnDayPrint.Click
        Dim Report As New frmReport
        objdata = New clsMSSQL
        isigroup = objdata.QueryDatabase("SELECT * FROM tblPlan WHERE plan_date >='" & dtpDate.Value.Date & "' ORDER BY plan_date")
        Myrpt.Load("..\..\Reports\Hmerisio.rpt")
        Call DataSourceConnection_Report()
        Report.Report1.ReportSource = Myrpt
        Report.Show()
    End Sub

Public Function QueryDatabase(ByVal Query As String) As DataTable
        Try
            Dim objDataSet As New DataSet
            Dim objDataTable As New DataTable
            Dim objDataAdapter As New SqlDataAdapter(Query, con)
            objDataAdapter.Fill(objDataSet, "DefaultTable")
            objDataTable = objDataSet.Tables("DefaultTable")
            con.Close()
            Return objDataTable
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Λάθος", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return DbSwtable
        End Try
    End Function


The report opens but but the data shows it is not according to the date that I give with datetimepicker
What am I doing wrong ?

Thanks in advance

The table is PlanID INT, Tactic nvarchar, Rookies nvarchar, Borders nvarchar, plan_date datetime
Posted
Updated 13-Jun-14 8:31am
v3
Comments
DamithSL 13-Jun-14 13:54pm    
update the question with QueryDatabase code
jomachi 13-Jun-14 13:59pm    
Hi my friend Ι informed the question

1 solution

VB
Public Function QueryDatabase(ByVal Query As String, Byval dt as DateTime) As DataTable
        Try
            Dim objDataSet As New DataSet
            Dim objDataTable As New DataTable
            Dim objDataAdapter As New SqlDataAdapter(Query, con)
            objDataAdapte.SelectCommand.Parameters.AddWithValue("@dt",dt)
            objDataAdapter.Fill(objDataSet, "DefaultTable")
            objDataTable = objDataSet.Tables("DefaultTable")
            con.Close()
            Return objDataTable
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Λάθος", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return DbSwtable
        End Try
    End Function

call it as
VB
isigroup = objdata.QueryDatabase("SELECT * FROM tblPlan WHERE plan_date >= @dt ORDER BY plan_date", tpDate.Value.Date)
 
Share this answer
 
Comments
jomachi 13-Jun-14 14:29pm    
I use your code but I have the same result. I will inform question with the database table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900