Private Sub GrdListFill(grdList As MSHFlexGrid) Dim cn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim rsVar As Variant Dim i As Integer cn.Open "Testing" '<-- Your DSN '打开你的数据库 Rs.Open "select * from CodeCustomerFile", cn, adOpenStatic, adLockOptimistic Rs.MoveLast Rs.MoveFirst With grdList .Rows = Rs.RecordCount + 1 rsVar = Rs.GetString(adClipString, Rs.RecordCount) .Cols = Rs.Fields.Count For i = 0 To Rs.Fields.Count - 1 .TextMatrix(0, i) = Rs.Fields(i).Name Next .Row = 1 .Col = 0 .RowSel = .Rows - 1 .ColSel = .Cols - 1 .Clip = rsVar .RowSel = .Row .ColSel = .Col Rs.Close Set Rs = Nothing cn.Close Set cn = Nothing End With End Sub
Dim Rs As New ADODB.Recordset
Dim rsVar As Variant
Dim i As Integer
cn.Open "Testing" '<-- Your DSN
'打开你的数据库
Rs.Open "select * from CodeCustomerFile", cn, adOpenStatic, adLockOptimistic
Rs.MoveLast Rs.MoveFirst
With grdList
.Rows = Rs.RecordCount + 1
rsVar = Rs.GetString(adClipString, Rs.RecordCount)
.Cols = Rs.Fields.Count
For i = 0 To Rs.Fields.Count - 1
.TextMatrix(0, i) = Rs.Fields(i).Name
Next
.Row = 1
.Col = 0
.RowSel = .Rows - 1
.ColSel = .Cols - 1
.Clip = rsVar
.RowSel = .Row
.ColSel = .Col Rs.Close
Set Rs = Nothing
cn.Close
Set cn = Nothing
End With
End Sub