Dim MSFlexGrid1
Dim a1, a2, a3, a4, z
Dim LocalBeginTime, LocalEndTime, DateTime
Dim oRs, n, i, sl, oCom, db, cn
Dim kj4, kj5, kj6
Dim MSHFlexGrid,objprocessBar,recordCount,objLoadText
db = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ShiFang;Data Source=.\WinCC"
Set cn = CreateObject("ADODB.Connection")
cn.ConnectionString = db
cn.CursorLocation = 3
cn.Open
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType =1
Set a1 = HMIRuntime.Screens("抽检查询").ScreenItems("sd")
Set a2 = HMIRuntime.Screens("抽检查询").ScreenItems("st")
Set a3 = HMIRuntime.Screens("抽检查询").ScreenItems("ed")
Set a4 = HMIRuntime.Screens("抽检查询").ScreenItems("et")
LocalBeginTime = Year(a1.Value)& "-" & Month(a1.Value) & "-" & Day(a1.Value) & " " & Hour(a2.Value) & ":" & Minute(a2.Value) & ":" & Second(a2.Value)
LocalEndTime = Year(a3.Value) & "-" & Month(a3.Value) & "-" & Day(a3.Value) & " " & Hour(a4.Value) & ":" & Minute(a4.Value) & ":" & Second(a4.Value)
sl="select * form EngineeringCode where DT between '"& LocalBeginTime&"' and '" & LocalEndTime&"' order by DT"
Set oCom.activeconnection = cn
oCom.CommandText = sl
Set oRs = oCom.Execute //执行不下去
n = oRs.RecordCount
MsgBox("共有" &n& "行数据")
Set MSFlexGrid1 = HMIRuntime.Screens("datachack").ScreenItems("MSHFlexGrid_1")
MSFlexGrid1.Clear
MSFlexGrid1.Col = 3
MSFlexGrid1.Rows = n + 1
MSFlexGrid1.ColAlignmentFixed = 3
MSFlexGrid1.ColAlignment(0) = 3
MSFlexGrid1.ColAlignment(1) = 3
MSFlexGrid1.ColAlignment(2) = 3
MSFlexGrid1.FormatString = "序号|时间|工程码"
MSFlexGrid1.ColWidth(0) = 1500
MSFlexGrid1.ColWidth(1) = 4000
MSFlexGrid1.ColWidth(2) = 12000
oRs.MoveFirst
For i = 0 To n
MSFlexGrid1.TextMatrix (i,0) = i
MSFlexGrid1.TextMatrix (i,1) = oRs.Fields(0).Value
MSFlexGrid1.TextMatrix (i,2) = oRs.Fields(1).Value
Next
Set oRs = Nothing
Set oCom = Nothing
cn.Close
Set cn = Nothing