Con="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WINCC_XIN;Data Source=.\WINCC"
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = Con
conn.CursorLocation = 3
conn.Open
sSql="SELECT * FROM 剧目 WHERE ID >'"&Data4&"'"
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandType = 1
oCom.CommandText = sSql
Set oRs = oCom.Execute
m=oRs.RecordCount
HMIRuntime.Tags("B").Write(m)
he=Key2&"00"&Value.Read
Set NodeIndex=TV.Nodes.Add(Key1,2,he,Input)
Do While Not oRs.eof
'For i=1 To m Step 1
Data11=oRs.Fields(2).Value
Data12=oRs.Fields(3).Value
Set Data15=HMIRuntime.Tags("转换场景")
Set Data16=HMIRuntime.Tags("转换CLAS")
Data15.Read
Data15.Write Data11
Data16.Read
Data16.Write Data12
Data13=HMIRuntime.Tags("转换场景").Read
Data14=HMIRuntime.Tags("转换CLAS").Read
TV.nodes.remove(Data16.Read )
Set NodeIndex=TV.Nodes.Add(Key2,4,Data16.Read ,Data15.Read)
sSql="SELECT * FROM "&Data13&""
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandType = 1
oCom.CommandText = sSql
Set oRs = oCom.Execute
Do While Not oRs.eof
Data21=oRs.Fields(1).Value
Data22=oRs.Fields(2).Value
Set Data25=HMIRuntime.Tags("要插入设备")
Set Data26=HMIRuntime.Tags("要插入CLAS")
Data25.Read
Data25.Write Data21
Data26.Read
Data26.Write Data22
Data23=HMIRuntime.Tags("要插入设备").Read
Data24=HMIRuntime.Tags("要插入CLAS").Read
Set NodeIndex=TV.Nodes.Add(Data14,4,Data24,Data23)
oRs.movenext
Loop
oRs.movenext
Loop
'Next i
Set oRs = Nothing
conn.Close
Set conn = Nothing
问题补充:
哪位大侠告诉我一下,为啥里面一个 DO WHILE........LOOP能循环,外面一个 DO WHILE........LOOP不循环呢
最佳答案
你这段代码没有出现死循环我都感觉很惊讶,你先将结果查询到oRs中,然后第二次查询结果又覆盖了oRs,你说代码会不会出错。你要同时访问两个查询结果,你是不是得有两套oRs用于存储你查询出来的记录集啊!!!
提问者对于答案的评价:
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc171474.html