我的代码如下:主要完成的功能是:要在画面中获得归档数据库中的数据,一共有四个I/O域,1号用于输入开始查询的时间,2号用于输入查询结束的时间,3号用于输入归档周期,这三个I/O域的输入格式都要参考wincc6.0专用归档命令所要求格式,4号用于输出查询结果.
Dim starttime
Dim endtime
Dim periodtime
Dim ConnectionObj
Dim Connectionstring
Dim CommandStr_TimeStart
Dim CommandStr_TimeEnd
Dim CommandObj
Dim RecordSetObj
Dim count
Dim resultt
Dim temp1
Dim temp2
starttime=HMIRuntime.Tags("TimeStart").Read
endtime=HMIRuntime.Tags("TimeEnd").Read
periodtime=HMIRuntime.Tags("TimePeriod").Read
HMIRuntime.Tags("Result").Write 0
'a=ScreenItems("shurushuchuyu1").OutputValue
'b=ScreenItems("shurushuchuyu2").OutputValue
'c=ScreenItems("shurushuchuyu3").OutputValue
Connectionstring="Provider=WinCCOLEDBProvider.1;Catalog=CC_sdsd_09_01_05_09_38_35R;Data
Source=.\WinCC"
CommandStr_TimeStart="Tag:R,'ProcessValueArchive\NewTag',0000-00-00 00:01:00.000','0000-00-
00 00:00:00.000'"
'CommandStr_TimeStart=CommandStr_TimeStart+"'"+starttime+"'"+","+"'0000-00-00 00:01:00.000'"
'CommandStr_TimeEnd="Tag:R,'ProcessValueArchive\NewTag',"'....'0000-00-00
00:01:00.000','0000-00-00 00:00:00.000'
'CommandStr_TimeEnd=CommandStr_TimeEnd+"'"+endtime+"'"+","+"'0000-00-00 00:01:00.000'"
MsgBox CommandStr_TimeStart
MsgBox CommandStr_TimeEnd
Set ConnectionObj=CreateObject("ADODB.Connection")
ConnectionObj.ConnectionString=Connectionstring
ConnectionObj.CursorLocation=3
ConnectionObj.Open
MsgBox Connectionstring
Set RecordSetObj=CreateObject("ADODB.Recordset")
Set CommandObj=CreateObject("ADODB.Command")
Set CommandObj.ActiveConnection=ConnectionObj
CommandObj.CommandType=1
CommandObj.CommandText=CommandStr_TimeStart
Set RecordSetObj=CommandObj.Execute
MsgBox "command...executing....1111"
temp1=RecordSetObj.Fields(2).Value
MsgBox "command...executed...1111"
'CommandObj.CommandText=CommandStr_TimeEnd
'Set RecordSetObj=CommandObj.Execute
'MsgBox "command...executing...2222"
'temp2=RecordSetObj.Fields(2).Value
'MsgBox "command...executed...2222"
count=RecordSetObj.Fields.Count
'MsgBox RecordSetObj.Fields(count).Name
MsgBox RecordSetObj.Fields(count-1).Name
MsgBox RecordSetObj.Fields(count-2).Name
MsgBox RecordSetObj.Fields(count-3).Name
MsgBox RecordSetObj.Fields(count-4).Name
MsgBox RecordSetObj.Fields(count-5).Name
MsgBox count,,"fields-count"
resultt=temp1-temp2
HMIRuntime.Tags("Result").Write resultt
MsgBox resultt
RecordSetObj.Close
Set RecordSetObj=Nothing
Set CommandObj=Nothing
ConnectionObj.Close
Set ConnectionObj=Nothing
按照这句查的时候: CommandStr_TimeStart="Tag:R,'ProcessValueArchive\NewTag',0000-00-00
00:01:00.000','0000-00-00 00:00:00.000'"
是可以查询出结果的,把0000-00-00 00:01:00.000改为0000-00-00 00:30:00.00也是可以查出结果的,但
只要把查询语句里的两个时间值改成一个时间值 ,比如2009-01-07 08:00:00.000,或者两都都改变,就查
不到数据了,测试的时候,错误的原因是因为返回的数据集为空,即EOF,不知道怎么原因,能否请大侠指点一
下!!!!!