时间:2019-05-06 标签:c#datatableselect语句带日期 [英] c# datatable select statement with dates

查看:122
本文介绍了时间:2019-05-06 标签:c#datatableselect语句带日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对数据表进行选择语句,以获取我正在查找的日期范围内的行.我是新手,我不太明白这个 select 语句是如何工作的.我试图写这个,但没有用.你能帮我一把吗?我卡住了

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+ '"');

推荐答案

除了用 # 包裹你的日期,如果 date1 是一个 DateTime 而不是一个字符串,你需要使用 ToString(你的日期格式)来获取正确的 sql陈述.如果首先创建一个包含过滤器的字符串,然后使用该字符串进行选择,那么调试会更容易.然后您可以查看字符串并在查询构建器中使用它来验证您的 sql.

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.

这篇关于时间:2019-05-06 标签:c#datatableselect语句带日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆