日历控件刚刚学会怎么弄,但是要查询这两个语句之间的数据的语法我但是较劲脑汁啊。在网上查。自己试,但是每次不是语法错误就是连接不上数据库,我感觉这种方法就在我的眼前,我就是弄不出来,煞费苦心啊。以下是查询两个日历控件之间的代码,大家能够看看。
<pre name="code" class="vb"><span style="font-size:18px;">Private Sub Command1_Click()
date1 = DTPicker1.Value
date2 = DTPicker2.Value
'比較两个日期的大小
If DateDiff("n", CDate(date1), CDate(date2)) < 0 Then
MsgBox "起始日期与结束日期有冲突,请又一次选择日期", , "提示"
Exit Sub
End If
Dim i, iCols As Integer '让全部列的文字都居中显示
iCols = MSFlexGrid1.Cols
For i = 0 To iCols - 1
MSFlexGrid1.ColAlignment(i) = flexAlignCenterCenter
Next
txtSQL = "select * from Recharge_Info where date between '" & date1 & "'" & " and '" & date2 & "'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
If mrc.EOF = True Then
MsgBox "没有信息"
Exit Sub
End If
With MSFlexGrid1
Do While mrc.EOF = False
.Rows = .Rows + 1
.TextMatrix(.Rows - 1, 0) = mrc!cardno
.TextMatrix(.Rows - 1, 1) = mrc!addmoney
.TextMatrix(.Rows - 1, 2) = mrc!Date
.TextMatrix(.Rows - 1, 3) = mrc!Time
.TextMatrix(.Rows - 1, 4) = mrc!userID
.TextMatrix(.Rows - 1, 5) = mrc!Status
mrc.MoveNext
Loop
End With
mrc.Close
End Sub
</span>
写了一大堆,事实上最实用的就是txtSQL语句这句话——
<pre name="code" class="vb">txtSQL = "select * from Recharge_Info where date between'" & Format$(date1, "yyyy - mm - dd") & "'" & " and'" & Format$(date2, "yyyy-mm-dd") & "'"
txtSQL = "select * from Recharge_Info where date >='" & date1 & "' and date <='" & date2 & "'"
上面的两句话写那句也行。看我们的不同须要了。此方法不仅能够比較日期,以此类推。基本上带数字的都能查询吧!事实上在数据这。我们把select 语句玩转了能够说把数据库也快玩转了。这个语法,与之前用等于号的语法比較起来,也有相似之处,有了相似,我们就好记了。