通过时间范围来查询数据库;
下面程序段;在VB中使用是正常的;但在IFIX的VBA中使用就不正常;
当选择开始和结束时间后;点查询后;得到查询结果;
而后再改变时间范围后;点查询后;就不起作用;还是以前第一次查询的结果!
不知道是什么原因?
查询代码如下:
Private Sub CheckSQL_Click()
Dim By, Bm, Bd
Dim Ny, Nm, Nd
Dim BeginDate
Dim EndDate
By = DTPicker1.Year
Bm = DTPicker1.Month
Bd = DTPicker1.Day
BeginDate = By & "-" & Bm & "-" & Bd & " " & "00:00:00"
Fix32.Fix.DT1.A_CV = BeginDate
Ny = DTPicker2.Year
Nm = DTPicker2.Month
Nd = DTPicker2.Day
EndDate = Ny & "-" & Nm & "-" & Nd & " " & "23:59:59"
Fix32.Fix.DT2.A_CV = EndDate
With Adodc1
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MAINDATA;Data Source=MICRO-4316EA8F9"
.CursorType = adOpenDynamic
.CommandType = adCmdText ‘将Source作为命令
.RecordSource = "SELECT * FROM ribao WHERE riqi BETWEEN ‘" & BeginDate & "‘and‘" & EndDate & "‘ORDER BY riqi"
‘ .Refresh
End With
Set DataGrid1.DataSource = Adodc1 ‘使用DataGrid的表;
DataGrid1.Refresh
Adodc1.Refresh
End Sub