WINCC V6教材中ADO/WINCC OLE DB访问数据库的实例

已锁定

瑞琦

  • 帖子

    232
  • 精华

    2
  • 被关注

    5

论坛等级:游侠

注册时间:2006-05-13

普通 普通 如何晋级?

WINCC V6教材中ADO/WINCC OLE DB访问数据库的实例

4419

57

2006-05-30 17:11:49

Private Sub Command3_Click()

Dim sPro As String
Dim sDsn As String
Dim sSer As String
Dim sCon As String
Dim sSql As String
Dim conn As Object
Dim oRs As Object
Dim oCom As Object
Dim oItem As ListItem
Dim m, n, s

'#为ADODB创建connection string

sPro = "Provider=WinCCOLEDBProvider.1;"
sDsn = "Catalog=CC_LQCHUCHE_06_03_31_12_39_23R;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer

'#在sSql定义命令文本(相对时间)

sSql = "TAG:R,'report\PIA1503 ','0000-00-00 00:10:00.000','0000-00-00 00:00:00.000'"
sSql = "TAG:R,1,'0000-00-00 00:10:00.000','0000-00-00 00:00:00.000'"
MsgBox "Open with:" & vbCr & sCon & vbCr & sSql & vbCr


'#建立连接

Set conn = CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = 3
conn.Open


'#使用命令文本进行查询

Set oRs = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Set oCom.ActiveConnection = conn
oCom.CommandText = sSql


'#填充记录集
Set oRs = oCom.Execute
m = oRs.Fields.Count


'#用记录集填充标准listview对象

ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(1).Name), 240
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(2).Name), 140
ListView1.ColumnHeaders.Add , , CStr(oRs.Fields(3).Name), 140
If (m > 0) Then
oRs.MoveFirst
n = 0
Do While Not oRs.EOF
n = n + 1
s = Left(CStr(oRs.Fields(1).Value), 23)
Set oItem = ListView1.ListItems.Add()
oItem.Text = Left(CStr(oRs.Fields(1).Value), 23)
oItem.SubItems(1) = FormatNumber(oRs.Fields(2).Value, 4)
oItem.SubItems(2) = Hex(oRs.Fields(3).Value)
If (n > 1000) Then Exit Do
oRs.MoveNext
Loop
oRs.Close
Else

End If

Set oRs = Nothing
conn.Close
Set conn = Nothing

End Sub
但是我在调试的时候还是报错.是哪里出了问题呢?
WINCC V6教材中ADO/WINCC OLE DB访问数据库的实例 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC WinCC / Panel

共有32913条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。