当前位置: 主页 > PLC控制

为啥在数据库中循环实现不了,两个循环嵌套在一起就循环不了了,如果把里面的循环去掉,就可以实现了。

Con="Provider=SQLOLEDB.1;integratedSecurity=SSPI;PersiSTSecurityInfo=False;InitialCatalog=wincc_XIN;DatASourCE=.\WINCC"
Setconn=CreateObject("ADODB.Connection")
conn.ConnectionString=Con
conn.CursorLocation=3
conn.Open
sSql="SELECT*FROM剧目WHEREID>’"&Data4&"’"
SetoRs=CreateObject("ADODB.Recordset")
SetoCom=CreateObject("ADODB.Command")
SetoCom.ActiveConnection=conn
oCom.CommandType=1
oCom.CommandText=sSql
SetoRs=oCom.Execute
m=oRs.RecordCount

HMIRuntime.Tags("B").Write(m)

he=Key2&"00"&Value.Read


SetNodeIndex=TV.NodES.Add(Key1,2,he,Input)


DoWhileNotoRs.eof
‘Fori=1TomStep1
Data11=oRs.Fields(2).Value
Data12=oRs.Fields(3).Value

SetData15=HMIRuntime.Tags("转换场景")
SetData16=HMIRuntime.Tags("转换CLAS")

Data15.Read
Data15.WriteData11
Data16.Read
Data16.WriteData12

Data13=HMIRuntime.Tags("转换场景").Read
Data14=HMIRuntime.Tags("转换CLAS").Read


TV.nodes.remove(Data16.Read)

SetNodeIndex=TV.Nodes.Add(Key2,4,Data16.Read,Data15.Read)

sSql="SELECT*FROM"&Data13&""

SetoRs=CreateObject("ADODB.Recordset")
SetoCom=CreateObject("ADODB.Command")
SetoCom.ActiveConnection=conn
oCom.CommandType=1
oCom.CommandText=sSql
SetoRs=oCom.Execute

DoWhileNotoRs.eof

Data21=oRs.Fields(1).Value
Data22=oRs.Fields(2).Value

SetData25=HMIRuntime.Tags("要插入设备")
SetData26=HMIRuntime.Tags("要插入CLAS")

Data25.Read
Data25.WriteData21
Data26.Read
Data26.WriteData22


Data23=HMIRuntime.Tags("要插入设备").Read
Data24=HMIRuntime.Tags("要插入CLAS").Read

SetNodeIndex=TV.Nodes.Add(Data14,4,Data24,Data23)


oRs.movenext
Loop

oRs.movenext
Loop
‘Nexti
SetoRs=Nothing
conn.Close
Setconn=Nothing

问题补充:
哪位大侠告诉我一下,为啥里面一个DOWHILE……..LOOP能循环,外面一个DOWHILE……..LOOP不循环呢

最佳答案

你这段代码没有出现死循环我都感觉很惊讶,你先将结果查询到oRs中,然后第二次查询结果又覆盖了oRs,你说代码会不会出错。你要同时访问两个查询结果,你是不是得有两套oRs用于存储你查询出来记录集啊!!!

提问者对于答案的评价:

  • 关注微信

猜你喜欢

微信公众号