本文介绍了DateTimePicker和Crystal报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我想用Crystal Report打印一个数据库表。

在表格中我有一个DateTimePicker(dtpDate)和一个带有此代码的按钮



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

 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





报告打开,但数据显示不符合我给datetimepicker的日期

我做错了什么?



提前致谢



table是PlanID INT,Tactic nvarchar,Rookies nvarchar,Borders nvarchar,plan_date datetime



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

推荐答案

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

isigroup = objdata.QueryDatabase("SELECT * FROM tblPlan WHERE plan_date >= @dt ORDER BY plan_date", tpDate.Value.Date)


这篇关于DateTimePicker和Crystal报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:18