Vs .net 2003 form dates parameters

lunedì 26 febbraio 2007 - 18.46

aleplgr Profilo | Junior Member

Hi! I'm trying to pass 2 dates parameters to my report from visual studio .net. And run it clicking a Run button. To do that I defined 2 formulas in my report, one for the initial date and the other for the final date, and then the record selection formula that uses this two formulas.
The intiial date formula is this one: DateTime (2005, 04, 18, 00, 00, 00), for example, for 18/04/2005
and the final is a similar one with the final date for the interval.
The record selection formula is this one:
({Orders.Order Date} > {@initial}) And ({Orders.Order Date}< {@final})

And this works!! I launch the report from vs.net 2003 and the selection formulas work fine.

I did this because now I need to add two DateTimePickers to the form, to get the initial and final dates values from the user.

I only have to add a Button to run the report and the 2 date pickers and this method in the Button Click:

Il codice sorgente non è stato renderizzato qui
perchè non c'è sufficiente spazio.
Clicca qui per visualizzarlo in una nuova finestra
But I get the errror message "Type CustomReportClass is not defined"

It seems an easy way to pass parameters, just defininig 2 formulas, and the code for the Run button, but there's something missing with this CustomReportClass, anyone did something like this that works?

freeteo Profilo | Guru

Hi,
sorry for this late answer.Anyway, i guess the problem is how u pass the value to the report in this lines of code:

>myReport.DataDefinition.FormulaFields("initial") = DateTimePicker1.Text
>myReport.DataDefinition.FormulaFields("final") = DateTimePicker2.Text

probably u have to set the right text to the formulaField, something like:
myReport.DataDefinition.FormulaFields("initial").Text = "Cdate(" + DateTimePicker1.Text + ")"
myReport.DataDefinition.FormulaFields("final").Text = "Cdate(" + DateTimePicker2.Text + ")"

in this way u set the formula text, like u can set in the designer, specifying the use of the function "Cdate", that u can find in the formula editor of report...
ciao.

Matteo Raumer
[MCAD .net]
http://blogs.dotnethell.it/freeteo

aleplgr Profilo | Junior Member

Almost!!!
Now it compiles, but shows a blank report. I think it's because the DateTimePickers date format is different than the formula date format in the report:

In the DateTimePickers I've selected the Short format : (for example today is represented like this: 04/03/2007)
In the report, the initial formula is represented like this: Date (1997, 04, 02), this is (YYYY,MM,DD) and the final formula is this: Date (1998, 04, 10)

and in the Click button I have this:
myReport.DataDefinition.FormulaFields("inicial").Text = "CDate(" + DateTimePicker1.Text + ")"
myReport.DataDefinition.FormulaFields("final").Text = "CDate(" + DateTimePicker2.Text + ")"

I think I need to convert one to the other I think that this should be done with the CDate, I need a CDate that converts the format DD/MM/YYYY to the format (YYYY, MM,DD) and can't find out how to do it

freeteo Profilo | Guru

hi,
I guess u can do it with string.Format method, i mean something like:

myReport.FormulaFields("final").Text = "CDate(" + string.Format("yyyy,MM,dd", DateTimePicker1.Text) + ")"

because the output of string.Format should be like the one u need...
ciao.

Matteo Raumer
[MCAD .net]
http://blogs.dotnethell.it/freeteo

aleplgr Profilo | Junior Member

Now I get this runtime error :
"Error in formula CDate (yyyy,MM,dd).
Missing )"
I modified it a little to compile it, Now it looks like this:

Il codice sorgente non è stato renderizzato qui
perchè non c'è sufficiente spazio.
Clicca qui per visualizzarlo in una nuova finestra


Why "missing )" ????
The String.Format gets the DateTimePicker2.Text and formats it like "yyyy,MM,dd" and that's what the "final" formula needs, there are no missing )
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5