如何进入日期之间 [英] How to get the in between dates
本文介绍了如何进入日期之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字段Billing_Month,其数据类型为String,Billing_Year为Int。
在我的表单中我有四个组合框,我想要的是从cboFromMonth和cboFromYear到cboToMonth和cboToYear之间的值。谁能帮我解决问题并给我一个示例查询?
提前谢谢。
解决方案
< blockquote>尝试:
使用 con As 新 SqlConnection(strConnect)
con.Open()
使用 cmd < span class =code-keyword> As 新 SqlCommand( SELECT String,Billing_Year FROM myTable WHERE Billing_Month BETWEEN @DS AND @DE,con)
DateTime dtStart = DateTime.ParseExact(cboFromYear.Text + cboFromMonth.Text, yyyydd,CultureInfo.InvariantCulture);
DateTime dtEnd = DateTime.ParseExact(cboToYear.Text + cboToMonth.Text, yyyydd ,CultureInfo.InvariantCulture);
cmd.Parameters.AddWithValue( @ DS,dtStart)
cmd .Parameters.AddWithValue( @ DE,dtEnd)
使用 reader As SqlDataReader = cmd.ExecuteReader()
while reader.Read()
...
结束 虽然
结束 使用
结束 使用
结束 使用
I have a field Billing_Month that has a data type String and Billing_Year which is Int.
In my form i have four combobox, what i want is to get the in between values from cboFromMonth and cboFromYear To cboToMonth and cboToYear. Can anyone help me to solve my problem and give me a sample query?
Thanks in advance.
解决方案
Try:
Using con As New SqlConnection(strConnect) con.Open() Using cmd As New SqlCommand("SELECT String,Billing_Year FROM myTable WHERE Billing_Month BETWEEN @DS AND @DE", con) DateTime dtStart = DateTime.ParseExact(cboFromYear.Text + cboFromMonth.Text, "yyyydd", CultureInfo.InvariantCulture); DateTime dtEnd = DateTime.ParseExact(cboToYear.Text + cboToMonth.Text, "yyyydd", CultureInfo.InvariantCulture); cmd.Parameters.AddWithValue("@DS", dtStart) cmd.Parameters.AddWithValue("@DE", dtEnd) Using reader As SqlDataReader = cmd.ExecuteReader() While reader.Read() ... End While End Using End Using End Using
这篇关于如何进入日期之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文