【问题标题】:Error in setting LinqDataSource Where Clause with datetime column使用日期时间列设置 LinqDataSource Where 子句时出错
【发布时间】:2014-02-21 08:53:18
【问题描述】:

我想在后面的代码中设置以下 linqdatasource where 子句。

<asp:LinqDataSource ID="lds" runat="server" ContextTypeName="dcDataContext"
    TableName="vStaff_Currents" OrderBy="Department,DisplayName" >
</asp:LinqDataSource>

在后面的代码中:

Dim filterString As String = ""

Dim AtDate As Date = Nothing

AtDate = Request("PeriodEnd").ToDate

filterString = "xxxxxxxxxxx"

filterString = filterString & "xxxxxxxxxxx"

lds.Where = filterString

我想在查询字符串 [Request("PeriodEnd")] 的 where 子句中插入日期时间条件

我尝试了不同的命令,但它返回错误

选项 1:

filterString = filterString & " and (RenumerationDate <= DateTime.Parse(" & AtDate & "))"

错误:

“日期时间”类型中不存在适用的方法“解析”

选项 2:

filterString = filterString & " and (RenumerationDate <= " & AtDate.ToString("dd-mm-yyyy") & " )"

错误:

运算符 '

如何在后面的代码中添加 where 子句?谢谢

【问题讨论】:

  • 您的“RenumerationDate”数据类型是什么?
  • 你好,数据类型是“日期时间”

标签: asp.net vb.net linq datetime where-clause


【解决方案1】:

解决办法是:

filterString = filterString & " and (RenumerationDate <= DateTime.Parse(""" & AtDate & """))"

【讨论】:

    【解决方案2】:

    试试这个方法

    filterString = filterString & " and (RenumerationDate <= " & DateTime.Parse(AtDate) & ")"
    

    filterString = filterString & " and (RenumerationDate <= " & Convert.ToDateTime(AtDate) & ")"
    

    【讨论】:

    • 谢谢。但它返回错误“运算符'
    猜你喜欢
    • 2010-12-29
    • 1970-01-01
    • 2014-11-11
    • 2010-12-28
    • 1970-01-01
    • 2018-11-03
    • 2011-01-04
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多