日期与C#DataTable的select语句 [英] c# datatable select statement with dates
问题描述
我试图做一个数据表的SELECT语句来获得这就是我正在寻找的日期范围内的行。我是新来这个的我不很明白这个SELECT语句是如何工作的。我试着写这一点,但不工作。你能不能在这里给我一只手。我坚持
foundRows = dt.Select(DATE1< ='+日期1 +'和date2> =' + DATE1 +'');
另外包装的以#日期,如果DATE1是一个DateTime,而不是一个字符串,你需要使用的ToString(您的日期格式),以获得正确的SQL语句。为了调试使其如果你首先创建一个包含过滤字符串很容易,然后做选择使用该字符串,然后你可以看一下字符串和使用,在查询生成器来验证你的SQL。
i am trying to make a select statement on a datatable to get the row that is within the date range i am looking for. I am new to this an i dont quite understand how this select statement works. I tried to write this but is not working. Can you please give me a hand here. I am stuck
foundRows = dt.Select("DATE1 <= '" + date1+ "' AND DATE2 >= '" + date1+ '"');
Besides wrapping your dates with #, if date1 is a DateTime and not a string, you need to use the ToString(your date format) to get the correct sql statement. For debugging it make it easier if first you create a string containing your filter, then do the select using that string. Then you can look at the string and use that in the query builder to validate your sql.
这篇关于日期与C#DataTable的select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!