Public conn As New ADODB.Connection
Public rs1 As New ADODB.Recordset
Public g_sql As String
if rs1.state=1 then rs1.close
g_sql="select * from table_name"
rs1.open g_sql,conn,3,1
with msflexgrid
for i=1 to rs1.recordcount
.textmatrix(i,0)=iif(isnull(rs1("字段1")),"",rs1("字段1")
.textmatrix(i,1)=iif(isnull(rs1("字段2")),"",rs1("字段2")
.
.
.
.textmatrix(i,n)=iif(isnull(rs1("字段n+1")),"",rs1("字段n+1")
rs1.movenext
.rows=.rows+1
next i
end with
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
with msflexgrid1
.rows=1 '第一列为表头,赋值与下面的类似
do while not rst.eof
.rows=.rows+1
.textmatrix(.rows-1,0)=rst.fields(0)
.textmatrix(.rows-1,1)=rst.fields(1)
'..........有几个字段就写几条
rst.movenext
loop
end with