按日期范围 [英] By date Range
本文介绍了按日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,
我希望这段代码在日期选择器中显示当前选择日期,但不会,但是如果我选择另一个复选框,它将显示所有交易,但是当我要选择"bydate"复选框时,它将不显示当前的选择日期,有人可以帮助我吗:D
Guys,
I want this piece of code to display the current pick date in the date picker but it won''t but it display all the transaction if I choose the other check box but when I want to choose the bydate checkbox it won''t display the current pick date can anyone help me with this please :D
ElseIf Me.ListBox1.Text = "Stock - IN" Then
If Me.chkAll.CheckState = CheckState.Checked Then
xSQL = "SELECT * FROM po"
Else
xSQL = "SELECT * FROM po WHERE PODate>" & "#" & Format(Me.dtFrom.Value, "MM/dd/yyyy") & "#" & "" & _
" AND PODate<" & "#" & Format(Me.dtTo.Value, "MM/dd/yyyy") & "#" & ";"
End If
If frmMain.PrintPO(xSQL) = True Then
frmReportViewer.strReport = "PO"
frmReportViewer.Show()
End If
ElseIf Me.ListBox1.Text = "Stock - OUT" Then
If Me.chkAll.CheckState = CheckState.Checked Then
xSQL = "SELECT * FROM sales"
Else
xSQL = "SELECT * FROM sales WHERE SalesDate>" & "#" & Format(Me.dtFrom.Value, "MM/dd/yyyy") & "#" & "" & _
" AND SalesDate<" & "#" & Format(Me.dtTo.Value, "MM/dd/yyyy") & "#" & ";"
End If
推荐答案
几件事;
1)使用SQL查询时,过去一直困扰着日期,所以我总是像``2010-Sep-10''这样过去日期
2)我注意到在SQL文本中您在右边添加了"?
您是否已将SQLtext转储到输出窗口以查看查询文本的确切样子?
我将上面的语句写为;
A couple of things;
1) I have been troubled with dates in the past when working with SQL queries, so I always past dates in like ''2010-Sep-10''
2) I notice in the SQL text you are adding a "" to the right?
Have you dumped the SQLtext to the output window to see exactly what the query text looks like?
I would write the statement above as;
xSQL = "SELECT * FROM sales WHERE SalesDate > '" & Format(Me.dtFromValue, "yyyy-MMM-dd") & "' AND SalesDate < '" & Format(Me.dtTo.Value, "yyyy-MMM-dd") & "';"
另外,您可能想看看如何创建参数化查询.
Also, you may want to look at creating paramaterised queries.
这篇关于按日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文