Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Date parameter problem from C# to CR11 Post Reply Post New Topic
Author Message
web007
Newbie
Newbie
Avatar

Joined: 07 Mar 2007
Location: United States
Online Status: Offline
Posts: 12
Quote web007 Replybullet Topic: Date parameter problem from C# to CR11
    Posted: 07 Mar 2007 at 1:22pm
HI All,
 
I am new to this site.
I am working on a Web Based project which uses Visual C#.Net, AsP.net and Crystal Reports 11.
 
problem:
 
I am sending two date parameters (startdate and enddate) from c#  to crystal report. Based on the dates, crystal report will be displayed the graph(pie chart).
 
Here is the code i have written :
 

string frmStg = "{Viewname.ColName} >= #" + startdate + "# AND {Viewname.ColName} <= #" + enddate + "#";

doc.DataDefinition.RecordSelectionFormula += frmStg ;

 
If I want search same date(for ex : 2007-01-23 to 2007-01-23) it is NOT working. If I change this to 2007-01-23 to 2007-01-24. It is WORKING.
 
Please help me how to search the dates using c# to cr11.
 
Thanks in Adavance.
 
web007
thanks
Web007
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 1:35pm
The problem is that your SQL dates have the time element in them. Thus, NO record is just "2007-01-23" instead it is like "2007-01-23  04:23:11 AM". You need to format the date field to drop off the time element from it.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
web007
Newbie
Newbie
Avatar

Joined: 07 Mar 2007
Location: United States
Online Status: Offline
Posts: 12
Quote web007 Replybullet Posted: 07 Mar 2007 at 1:43pm
BrianBischof ,
 
Thanks for your quick response.
 
Where do I have to change the format?
 
Is it in CR11, (startdate, enddate parameter data type is date).
or
if it is in C#. i am selecting the date from calendar contol(javascript) with YYYY-MM-DD format.
 
please guide me.
 
thanks.
 
thanks
Web007
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 1:58pm
You have to set it in the record selection formula of the crystal report. Since you are overriding the selection formula in your C# code with frmStg, then that is where you would put it.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
web007
Newbie
Newbie
Avatar

Joined: 07 Mar 2007
Location: United States
Online Status: Offline
Posts: 12
Quote web007 Replybullet Posted: 07 Mar 2007 at 2:34pm
BrianBischof ,
 
Thanks for your reply.
I have added a record selection formula in crystal report.
{viewname.colname} in {?startdate} to {?enddate}
It is showing some results. But in my applciation it is
promting the dialog box.
 
How to disable this prompting date calender window.
I tried to change startdate parmater as Cdate(#startdate#) for formatting.
 
Still No luck.. sorry to bother you.
Can you please give a example how to convert the dateformat?
 
thanks a lot.
thanks
Web007
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 3:29pm
I don't have time to create a new project and test it for this circumstance. But I should be able to get you going without too much trouble.

What I do when I have trouble figuring out why my formula string in .NET isn't working is to create the formula in Crystal Reports and then look at it in the Formula Workshop (there is a button on the dialog box). So what you should do is first get this working in Crystal Reports perfectly. Then look at the formula and save it to Notepad or someplace. You've done this and showed it in your last post.

Then go into your .NET app and build the string to match the formula EXACTLY. I see that you have '#' around your dates, but this isn't what you'll see in the Crystal Reports formula. So don't put it in the .NET one. Every character should match identically in your .NET string when you override the formula property. 

The problem I see with your code is that you said that you changed the ?startdate parameter. You shouldn't change anything. Make it identical to what Crystal Reports created on its own otherwise Crystal won't like it.

In this formula I use the DateValue() function to strip out the time portion.
DateValue({myTable.DateField}) IN {?startdate} to {?enddate}


Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 07 Mar 2007 at 3:39pm
Oh yeah, if you are getting the dates within C# and wanting to hardcode them into directly into the selection formula, then try this (assuming I don't screw up the double quotes)

frmStg=String.Format("DateValue({myTable.DateField}) IN DaveValue(""{0}"") to DateValue(""{1}"")", startdate, enddate);
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
web007
Newbie
Newbie
Avatar

Joined: 07 Mar 2007
Location: United States
Online Status: Offline
Posts: 12
Quote web007 Replybullet Posted: 07 Mar 2007 at 4:31pm
BrianBischof
 
Thanks a lot.. I am working on that.
Thanks for your time and help.
 
 
thanks
Web007
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.