下面是我在wincc全局脚本中的全部编辑代码,麻烦各位帮忙看看为什么我就是连接不上数据库,我看网上有很多类似的代码,我试了试都读不出数据,麻烦各位帮忙看看
Sub OnOpen(Byval Item)
Dim strcn
Dim cn
Dim isSQL
Dim com
Dim comSQL
Dim rds
Set cn = CreateObject ("ADODB.Connection")
strcn = "Provider = SQLOLEDB.1; Catalog = CC_0402_13_07_15_20_25_08R; Data Source = .\WINCC"
cn.ConnectionString = strcn
cn.CursorLocation = 3
cn.open
comSQL = "TAG:R,'SpeedAndAngel\Xjiaodu','2013-08-10 01:00:00.000','2013-08-31 01:00:00.000'"
Set rds = CreateObject ("ADODB.Recordset")
Set com = CreateObject ("ADODB.Command")
Dim m
com.ActiveConnection = strcn
com.CommandText = comSQL
Set rds = com.Execute
m = oRs.Fields.Count
Dim ListView1
Dim Litem
Set ListView1 = ScreenItems ("ListView1")
ListView1.ListItems.Clear ()
ListView1.ColumnHeaders.Clear ()
ListView1.GridLines = True
ListView1.ColumnHeaders.Add , , CStr(rds.Fields(0).Name), 50
ListView1.ColumnHeaders.Add , , CStr(rds.Fields(1).Name), 50
ListView1.ColumnHeaders.Add , , CStr(rds.Fields(2).Name), 50
ListView1.ColumnHeaders.Add , , CStr(rds.Fields(3).Name), 50
ListView1.ColumnHeaders.Add , , CStr(rds.Fields(4).Name), 50
Set Litem = ListView1.ListItems.Add ()
Litem.Text = CStr(rds.EOF)
Litem.SubItems (1) = CStr(rds.Fields(1).Value)
If (m > 0) Then
rds.MoveFirst
maxLine = 10
n = 0
Do While (Not rds.EOF And n < maxLine)
n = n + 1
s = Left(CStr(rds.Fields(1).Value), 23)
If (n > 1) Then Exit Do
rds.MoveNext
Loop
rds.Close
Else
End If
Set rds = Nothing
cn.Close
Set cn = Nothing
End Sub