I can show information by specific ID there in crystal report by following code.

Code :

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form6
Inherits System.Windows.Forms.Form


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Dim cryRpt As New ReportDocument
'cryRpt.Load(Application.StartupPath & "\CrystalReport5.rpt")
'CrystalReportViewer1.ReportSource = cryRpt
'CrystalReportViewer1.Refresh()

Dim cryRpt As New ReportDocument
cryRpt.Load(Application.StartupPath & "\CrystalReport5.rpt")

Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue

crParameterDiscreteValue.Value = TextBox1.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("id")
crParameterValues = crParameterFieldDefinition.CurrentValues

crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
cryRpt.RecordSelectionFormula = "{Button1}= " & TextBox1.Text & ""
End Sub

But I got a problem. I have a table where it has three fields. One for date one for income & another for expense. To show it I have a form two text boxes & one crystal report viewer. My problem is that to show a record of specific date is easy & I can do it by previous code. But according to user he wants to input starting date & end date to see records. So what should I do now? Can you please help me to do it? For example he needs to input starting date 1-1-2010 & end date 30-1-2010 & he wants to see all reports of January month including 1-1-2010 & 30-1-2010. I guess I have to create between clause in my query. But I am confused how should I create it? I have created two parameters. One is starting date & another is end date. What should I write there in formula workshop? For one parameter I had written this type of formula {asst.dt} = {?dt} but what should I write for two dates & how should I use between clause? I need help please help me.

This is an example of how to use the BETWEEN condition in an SQL query.

SELECT *
FROM orders
WHERE order_date BETWEEN to_date ('2010/01/01', 'yyyy/mm/dd')
AND to_date ('2010/01/30', 'yyyy/mm/dd'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.