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
但是我在调试的时候还是报错.是哪里出了问题呢?