vishwa vishwa - 3 months ago 14
Vb.net Question

How to use selection formula for crystal report for datetime column un vb.net

My problem is,How to set value to selection formula in crystal report for datetime column(im using sql server 2000).
eg:

selectionFromula="{tblMain.bday}='"& datetimepicker.value &"'"


when i use this, a error message is showing problem with selection formula.but when i use for another column,it work well like this,

selectionFormula="{tblMain.id}='"& txtid.text &"'"


but when it use for datetime type column,it doesn't work.can some one give me a working example for this.thanks

Answer

You are sending a string literal to the selection formula instead of a date. So, for example, if the datetimepicker.value is "1/1/2000", then Crystal would see

{tblMain.bday}='1/1/2000'

Either the string needs to be converted to a date value, or it needs to be flagged as a date literal using the pound sign (#).

One of these should be what Crystal sees.

//Using a conversion to a Crystal Date
{tblMain.bday}=CDate('1/1/2000')

//Using the Crystal Date literal
{tblMain.bday}=#1/1/2000#

So your selection formula in VB would look like one of these

'Using a conversion to a Crystal Date
selectionFormula="{tblMain.bday}=CDate('"& datetimepicker.value &"')"

'Using the Crystal Date literal
selectionFormula="{tblMain.bday}=#"& datetimepicker.value &"#"
Comments