按钮 代码如下 点击后把数据显示到mshflexgrid控件中,怎么无显示?
ub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y)
On Error Resume Next
Dim strConnectionString
Dim objConnection
Dim objCommand
Dim strSQL
Dim Rs
Dim MSHFlexGrid
strConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security InfO=False;Initial CataloG=CC_B_10_12_27_09_20_15R;Data SourcE=.\WinCC"
Set objConnection=CreateObject("ADODB.Connection")
objConnection.ConnectionString=strConnectionString
objConnection.Open
Set objCommand=CreateObject("ADODB.Command")
With objCommand
objCommand.ActiveConnection=objConnection
objCommand.CommandText= "select * from UA#formula"
End With
Set Rs=CreateObject("ADODB.Recordset")
Rs.Open objCommand,,1,3
Set MSHFlexGrid=ScreenItems("MSHFGD_1")
Set MSHFlexGrid.DataSource=Rs
MSHFlexGrid.Refresh
Rs.Close
objConnection.Close
Set objCommand=Nothing
Set Rs=Nothing
Set objConnection=Nothing
Set MSHFlexGrid=Nothing
End Sub
问题补充:
数据库内有数据且数据库名称也对的
最佳答案
你首先得确定数据库查询是否正确?Rs记录集中是否有数据?参考:
http://www.ad.siemens.com.cn/service/answer/solution.asp?Q_id=62676&cid=1032
http://www.ad.siemens.com.cn/service/answer/solution.asp?Q_id=62488&cid=1032
提问者对于答案的评价:
OK
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc267064.html