设置在哪里使用DATETIME列条款的使用LinqDataSource [英] Setting the LinqDataSource Where Clause using DateTime Column
问题描述
在C#.NET,我有以下数据源的设置,我想要动态分配一个WHERE子句中的code后面......
In C#.net, I have the following DataSource setup that I am trying to dynamically assign a WHERE clause to in the code behind...
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="MyNameSpace.DataClasses1DataContext"
TableName="MyTableWithADateTimeColumn" >
</asp:LinqDataSource>
在code后面看起来是这样的...
The code behind looks something like this...
LinqDataSource1.Where = "MyDateColumn == DateTime(" + DateTime.Now + ")";
这给了我的')'错误或','预计
。我也试着在引号铸造的,还有,因为没有强制转换为DateTime和用引号引起来...
This gives me an error of ')' or ',' expected
. I've also tried casting it inside quotation marks, as well, as without casting it as DateTime and with quotation marks...
LinqDataSource1.Where = @"MyDateColumn == """ + DateTime.Now + @""" ";
这给了我运算符==与操作数类型日期时间和串不兼容
。我尝试了一些其他的方式,但我显然失去了一些东西。
This gives me Operator '==' incompatible with operand types 'DateTime' and 'String'
. I've tried several other ways, but I am obviously missing something here.
类似code工作正常字符串。
Similar code is working fine for strings.
推荐答案
是它呢?这件怎么样,然后...
is it this? What about this then...
LinqDataSource1.Where = "MyDateColumn == DateTime.Parse(" + DateTime.Now + ")";
//can't create a date from string in constructor use .Parse()...
这篇关于设置在哪里使用DATETIME列条款的使用LinqDataSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!