发表于:2011-12-19 13:00:46
楼主
Option Explicit
Function action
Dim sCon
Dim sSql
Dim conn
Dim oRs
Dim oCom
Dim i
Dim temvalue,objtag
‘sCon = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=CTMDBN;Data SouRCe=192.168.1.11"
sCon="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=CTMDBN;Data Source=192.168.1.11"
sSql = "SELECT Temperature FROM channelinfo"
‘ 2.1 Make connection
Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.Open
‘ 2.2 Use command text for query
Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql
‘ 2.3 Fill the recordset
Set oRs = oCom.Execute
‘ 3.0 Fill standard iofields object with recordset
i=0
Do While oRs.eof=False
temvalue=oRS.Fields(0).Value
i=i+1
HMIRuntime.Tags("t"&i).Write temvalue
oRs.movenext
Loop
Set oRs = Nothing
conn.Close
Set conn = Nothing
End Function