Wincc读取远程非wincc数据库 点击:333 | 回复:0



工控老鬼

    
  • 精华:47帖
  • 求助:0帖
  • 帖子:73帖 | 256回
  • 年度积分:0
  • 历史总积分:7275
  • 注册:2006年5月12日
发表于: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 

 


热门招聘
相关主题

官方公众号

智造工程师