下面是一项目函数,在按钮中调用;将其数据显示到listView控件中,但是程序执行到oRs=oCom.Execute处就停止了 是怎么回事 ?
Sub procedure1(sSql_1,sSql_2)
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
'Dim sSq1_1
'Dim sSq1_2
Dim oRs
Dim conn
Dim oCom
Dim oItem
Dim m, n, s
Dim hourdate
Dim secdate
Dim k
Dim ListView1
Dim ListView2
ScreenItems("statusbar").Text="正在打开数据库......"
sCon ="Provider=SQLOLEDB.1;"&_
"Integrated Security=SSPI;"&_
"Persist Security InfO=False;"&_
"Initial CataloG=CC_fortest_10_08_22_10_02_39R;"&_
"Data SourcE=.\WinCC"
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
ScreenItems("statusbar").Text="报表查询......"
'查询一
oCom.CommandText = sSql_1
MsgBox("a")
Set oRs=oCom.Execute'此处开始不执行了??
MsgBox("b")
Set ListView1=ScreenItems("ListView1")
ListView1.View =3
ListView1.ListItems.Clear
MsgBox("c")
'm = oRs.RecordCount
'ScreenItems("静态文本1").Text="查询结果 " & oRS.RecordCount & "个。"
MsgBox("d")
With ListView1
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "序号",60'ID
ListView1.ColumnHeaders.Add , , "日期", 70
ListView1.ColumnHeaders.Add , , "时间", 70
.......
Set oRs = Nothing
conn.Close
Set conn = Nothing
'MsgBox "查询完毕"
End Sub
请问为何执行那到oRs=oCom.Execute处就停止了呢?
最佳答案
1) 你用msgbox ssql_1看看这个参数有没有传进来
2) 把Set oRs=oCom.Execute换成oRs.open ssql_1,conn试试
提问者对于答案的评价:
谢谢
已经找到原因:sSql_1命令有问题!
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc267166.html