在WinCC中,我想通过查询将WinCC自带的SQL Server中的数据显示到MSFlexGrid控件上,但是老是不成功,请各位帮我看看有什么错误。
Set objCon=CreateObject("ADODB.Connection")
strCon = "DRIVER={SQL server};SERVER=LINLIN-PC\WINCC;DATABASE=report"
objCon.ConnectionString=strCon
objCon.open
HMIRuntime.Trace strCon & vbCrLf
Set objRes=CreateObject("ADODB.Recordset")
Set objCom=CreateObject("ADODB.Command")
a=HMIRuntime.Tags("aa1").Read
b=HMIRuntime.Tags("aa2").Read
strSql="Select * from zg where 序号<= b AND 序号>= a"
HMIRuntime.Trace strSql & vbCrLf
With objCom
.ActiveConnection=objCon
.CommandText=strSql
End With
Set objRes=objCom.Execute
Dim k
objRes.movefirst
k=1
Do While Not objRes.EOF
MSFlexGrid1.TextMatrix(k,1)=CStr(objRes.Fields(0).Value)
MSFlexGrid1.TextMatrix(k,2)=CStr(objRes.Fields(1).Value)
MSFlexGrid1.TextMatrix(k,3)=CStr(objRes.Fields(2).Value)
MSFlexGrid1.TextMatrix(k,4)=CStr(objRes.Fields(3).Value)
MSFlexGrid1.TextMatrix(k,5)=CStr(objRes.Fields(4).Value)
MSFlexGrid1.TextMatrix(k,6)=CStr(objRes.Fields(5).Value)
objRes.movenext
k=k+1
Loop
HMIRuntime.Trace strSql & vbCrLf
Set objCom=Nothing
objCon.Close
Set objRes=Nothing
Set objCon=Nothing
End Sub