如何使用用于日期时间列的水晶报告的选择公式 un vb.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13662248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use selection formula for crystal report for datetime column un vb.net
提问by vishwa
My problem is,How to set value to selection formula in crystal report for datetime column(im using sql server 2000). eg:
我的问题是,如何为日期时间列的水晶报告中的选择公式设置值(我使用 sql server 2000)。例如:
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
但是当它用于日期时间类型列时,它不起作用。有人可以为此提供一个工作示例吗?谢谢
回答by EvilBob22
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
您正在向选择公式发送字符串文字而不是日期。因此,例如,如果 datetimepicker.value 是“1/1/2000”,那么 Crystal 会看到
{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
所以你在 VB 中的选择公式看起来像以下之一
'Using a conversion to a Crystal Date
selectionFormula="{tblMain.bday}=CDate('"& datetimepicker.value &"')"
'Using the Crystal Date literal
selectionFormula="{tblMain.bday}=#"& datetimepicker.value &"#"

