Asked by:
Crystal Reports, Date Parameter

Question
-
User182458557 posted
Hi All,
I've written many crystal reports I have them them running through my ASP.net 2.0 website (c#). The non-parameter reports work great but I'm having trouble with the parameter reports. I know I can pass the report the parameters but I don't want to do that (much extra logic in the backend to figure out what i'm passing, date, vendor, client, inventory item ect ect).
When I run my parametered reports, it prompts me for the parameters but when I click on the button to select my dates it comes up with a ton of errors. Can I get your thoughts on running parameters this way,
TimWednesday, February 13, 2008 3:36 PM
All replies
-
User-982972619 posted
Hi tbraga, I think I have the answer for your problem dude. You said you want to pass a date parameter I can give you some solution I suppose:
--First, If you want your report by default showing the date that you want, you can use "Record Selection Formula Editor" you can find it in right click in the blank space of your report then choose Report>>Edit Selection Formula>>Records...
After that you can put this formula:
{Table1.DateShipments} = #27/12/2007# or if your field database isn't a datetime type you can use: Date({Table1.DateShipments}) = #27/12/2007#
Or if you want to give a date range write this down {Table1.DateShipments} >= #27/12/2007# and {Table1.DateShipments} <= #1/1/2008#--Secondly, if you want to pass the parameter from the webform, well let say you have a datetime picker and when you choose the date you pass the date to a textbox and click the submit button, you can use this:
1 private void Button1_Click(object sender, System.EventArgs e) 2 { 3 if(TxtDate1.Text !="" && TxtDate2.Text!="") 4 { 5 CrystalReportViewer1.Visible = true; 6 CrystalReportViewer1.SelectionFormula = " Date({Table1.DateShipments})>= #" + TxtDate1.Text+ "# And Date({able1.DateShipments})<= #" + TxtDate2.Text + "#"; 7 CrystalReportViewer1.RefreshReport(); 8 } 9 }
That code above if you want to give a range on your date parameter, if you don't you just simply put only one text box.
Good luck dude hope it helps, let me know if it's work out for you.
Regards.
--Please put Mark as Answer, if my post helps you Thanks. Good Luck.
Wednesday, February 13, 2008 9:29 PM -
User1786236466 posted
Hi,
I am having a strange problem in Crystal report 2008. Earlier I was using VS 2005 Crystal report. Then we purchased Crystal report 2008.When I open the VS 2005 projects it asks the reports to convert into Crystal report 2008. I did that.
Earlier I was using the following syntax for passing the date as selectionFormula
Dim selectionFormula As String = "{tblClient.Name} = '" & ddlClient.SelectedItem.Text & "' and {TBILL_File_Format.Week Ending Date} = #" _& Convert.ToDateTime(DtCtrlProDateFrom.DateTimeValue) & "#” WeeklyReportByClientNameReport.DataDefinition.RecordSelectionFormula = selectionFormula
But now when I run this same it says
This field name is not known. Details: errorkind Error in the file rptWeeklyReport.rpt: Error in formula Record_selection:
‘{tblClient.Name} = 'ABC10' and "{TBILL_File_Format.Week Ending Date} = #04/20/2008#’ This field name is not known. Details: errorkindI have no idea about this
Even If I tried to pass as followsselectionFormula = "{TBILL_File_Format.Week Ending Date} = DateTime (2008, 04, 25, 00, 00, 00) and {TBILL_File_Format.Client Code} = 'ABC10' "
I couldn’t see any record on the report except Grouptree of the report. If I export the report it has all the data as I expected.Please help me out on this regards.
Thanks in advanceSaravanan
Thursday, April 24, 2008 9:26 AM -
User1206846645 posted
You should create ParameterFieldDefinitions before passing arguments
ParameterFieldDefinitions crParameterFieldDefinitions ; ParameterFieldDefinition crParameterFieldDefinition ; ParameterValues crParameterValues = new ParameterValues(); ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = textBox1.Text; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions["fromDate"]; crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear(); crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crParameterDiscreteValue.Value = textBox2.Text; crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields; crParameterFieldDefinition = crParameterFieldDefinitions["toDate"]; crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-date-to-date.htm
lev
Friday, February 14, 2014 1:29 AM