自己从网上找了一个实例,自定义数据库,可以实现写入数据和读出数据。但是不能将查询结果在msflexgrid控件或者datagrid控件上显示出来,代码如图片所示。
问题补充:
代码如上传的图片所示
图片说明:
最佳答案
图呢?
datagrid,数据源的方式没测试过;
给你1段msflexgrid的代码:(一直使用的,没有任何问题)
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CRTest;Data Source=.\WinCC;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=FF-PC;Use Encryption for Data=False;Tag with column collation when possible=False;"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objRecordset = CreateObject("ADODB.Recordset")
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
strSQL = "select * from MinuteTable WHERE (dy between ''"&cb1.Text&"-"&cb2.Text&"-"&cb3.Text&" 00:00:00.000'' and ''"&cb1.Text&"-"&cb2.Text&"-"&cb3.Text&" 23:59:59.500'') ORDER BY dy DESC"
objCommand.CommandText = strSQL
Set objRecordset = objCommand.Execute
objCommand.Execute
Dim i
If (objRecordset.Bof And objRecordset.Eof) Then
MsgBox("没有符合要求的记录")
Else
i=0
While Not objRecordset.EOF
i=i+1
''If (objRecordset.Fields(1).Value <> "NULL") Then
MSFlexGrid1.TextMatrix(i, 1) = CStr(objRecordset.Fields(0).Value)
''End If
If (objRecordset.Fields(2).Value <> "NULL") Then
MSFlexGrid1.TextMatrix(i, 2) = CStr(objRecordset.Fields(2).Value)
End If
If (objRecordset.Fields(3).Value <> "NULL") Then
MSFlexGrid1.TextMatrix(i, 3) = CStr(objRecordset.Fields(3).Value)
End If
If (objRecordset.Fields(4).Value <> "NULL") Then
MSFlexGrid1.TextMatrix(i, 4) = CStr(objRecordset.Fields(4).Value)
End If
If (objRecordset.Fields(5).Value <> "NULL") Then
MSFlexGrid1.TextMatrix(i, 5) = CStr(objRecordset.Fields(5).Value)
End If
objRecordset.movenext
Wend
End If
''objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
提问者对于答案的评价:
原来是未对MSFlexGrid控件进行定义,Dim MSFlexGrid1 Set MSFlexGrid1=ScreenItem("控件1")。 感谢您的及时回答
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc357183.html