linq ASP.NET C#中的Between子句 [英] Between clause in linq ASP.NET C#
本文介绍了linq ASP.NET C#中的Between子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我想在asp.net c#中使用Linq之间的条款。
我的尝试:
Dear All,
I want use between clause using Linq in asp.net c#.
What I have tried:
if(txtFromdate.Text != "" && txtTodate.Text != "")
{
DateTime fromDate = Convert.ToDateTime(txtFromdate.Text);
DateTime toDate = Convert.ToDateTime(txtTodate.Text);
_candidates = from c in _candidates
where c.Registration >= fromDate && c.Registration <= toDate
select c;
}
但上面的代码没有返回任何记录。
任何人都可以帮助我。
提前致谢。
but the above code is not returning any record.
Can any one plz help me.
Thanks in advance.
推荐答案
public class candidates
{
public string Name;
public string Dept;
public string ID;
public DateTime Registration;
}
class Program
{
static void Main(string[] args)
{
DateTime fromDate = new DateTime(2017, 7, 31, 9, 30, 0);
DateTime toDate = new DateTime(2017, 7, 31, 11, 00, 0);
List<candidates> _candidate = new List<candidates>();
for (int i = 0; i <= 5; i++)
{
candidates c = new candidates();
c.Dept = "ABC";
c.ID = i.ToString();
c.Name = "Candidate " + i.ToString();
c.Registration = new DateTime(2017, 7, 31, 14-i, 00, 0);
_candidate.Add(c);
}
var _icandidates = from c in _candidate where c.Registration >= fromDate
&& c.Registration <= toDate select c;
}
这篇关于linq ASP.NET C#中的Between子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文