我想在代码后面设置以下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
我想在querystring [Request("PeriodEnd")]
我尝试了不同的命令,但它返回错误
选项1:
filterString = filterString & " and (RenumerationDate <= DateTime.Parse(" & AtDate & "))"
错误:
“DateTime”
类型中没有适用的方法“Parse”选项2:
filterString = filterString & " and (RenumerationDate <= " & AtDate.ToString("dd-mm-yyyy") & " )"
错误:
运算符'&lt; ='与操作数类型'DateTime不兼容?'和'Int32'
如何在代码中添加where子句?感谢
答案 0 :(得分:1)
解决方案是:
filterString = filterString & " and (RenumerationDate <= DateTime.Parse(""" & AtDate & """))"
答案 1 :(得分:0)
试试这种方式
filterString = filterString & " and (RenumerationDate <= " & DateTime.Parse(AtDate) & ")"
或
filterString = filterString & " and (RenumerationDate <= " & Convert.ToDateTime(AtDate) & ")"