VB6.0 MSHFlexGrid控件添加数据三种方法
1.绑定到数据源
程序代码
Option Explicit
Dim objConn As ADODB.Connection
Dim objRs As ADODB.Recordset
Private Sub Form_Load()
On Error Resume Next
Set objConn = New ADODB.Connection
Set objRs = New ADODB.Recordset
objConn.ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;DataSource=' & App.Path & '\demo3.mdb;'
objConn.Open
objRs.CursorLocation = adUseClient
objRs.Open 'Select ProductId,ProductName,Discontinued FROMProducts', objConn, adOpenStatic, adLockReadOnly
Set MSHFlexGrid1.DataSource = objRs
If Err.Number <> 0 Then
MsgBox Err.Description
End If
On Error GoTo 0
End Sub
'释放资源
Private Sub Form_Unload(Cancel As Integer)
'不操作此步会出错:The current row is not available
If TypeName(MSHFlexGrid1.DataSource) <> 'Nothing' Then
Set MSHFlexGrid1.DataSourc
赞 (0)