-
先看正常
代码:
Dim
con
As
New
ADODB.Connection
'
定义数据库的连接存放数据和代码
Dim
cmd
As
New
ADODB.Command
Dim
Gs
As
New
ADODB.Recordset
Dim
strSQL
As
String
con.ConnectionString
=
StrConn
strSQL
=
"
select * from 顾客信息表
"
'
con.CursorLocation = adUseClient'无就不能绑定数据了?
con.CursorLocation
=
adUseClient
'
还不能是adUseServer
con.Open
Set
Gs
=
con.Execute(strSQL)
'
Gs.Open strSQL, con, 3, 3
Set
DataGrid1.DataSource
=
Gs
DataGrid1.Refresh
'
Call FillDataToMSFlex(Gs, MSFlexGrid1)
Set Gs = N
othing
Set
con
=
Nothing
Dim
con
As
New
ADODB.Connection
'
定义数据库的连接存放数据和代码
Dim
cmd
As
New
ADODB.Command
Dim
Gs
As
New
ADODB.Recordset
Dim
strSQL
As
String
con.ConnectionString
=
StrConn
strSQL
=
"
select * from 顾客信息表
"
'
con.CursorLocation = adUseClient'无就不能绑定数据了?
con.CursorLocation
=
adUseClient
'
还不能是adUseServer
con.Open
Set
Gs
=
con.Execute(strSQL)
'
Gs.Open strSQL, con, 3, 3
Set
DataGrid1.DataSource
=
Gs
DataGrid1.Refresh
'
Call FillDataToMSFlex(Gs, MSFlexGrid1)
'
Set Gs = Nothing
'
Set con = Nothing
Gs.Close
con.Close
Public
Sub
FillDataToMSFlex(rs
As
ADODB.Recordset, Mygrid
As
MSFlexGrid)
'
将数据填充到MSFLEXGRID控件中去
Dim
i, j
As
Integer
Dim
RowCount
As
Integer
Mygrid.AllowUserResizing
=
flexResizeBoth
Do
Until rs.EOF()
Mygrid.Cols
=
rs.Fields.Count
+
1
Mygrid.TextMatrix(
0
,
0
)
=
"
序号
"
For
i
=
1
To
rs.Fields.Count
Mygrid.TextMatrix(
0
, i)
=
rs.Fields(i
-
1
).Name
Next
i
Mygrid.Rows
=
RowCount
+
1
Mygrid.TextMatrix(RowCount,
0
)
=
RowCount
For
j
=
0
To
rs.Fields.Count
-
1
If
IsNull
(rs.Fields(j))
Then
Mygrid.TextMatrix(RowCount, j
+
1
)
=
"
NULL
"
Else
Mygrid.TextMatrix(RowCount, j
+
1
)
=
rs.Fields(j)
End
If
Next
j
'
Mygrid.TextMatrix(RowCount, j + 1) = Trim(RecordValue(j))
RowCount
=
RowCount
+
1
rs.MoveNext
Loop
End Sub














Set Gs = N


现在做如下修改:


















会出现datagrid里没有数据.
那我再想Set gs=nothing 和gs.close到底有什么区别,我看了下百度Nothing,如下就是其解释:
Nothing 关键字用于取消某对象变量与实际对象的关联。使用 Set 语句将对象变量赋值为 Nothing。例如:
Set MyObject = Nothing
多个对象变量可以引用同一个实际对象。当 Nothing 赋值给某对象变量后,此变量就不再引用任何实际对象。当多个对象变量引用同一个对象时,只有在所有对象变量都设置为 Nothing (在设置为 Nothing 的最后一个对象变量超出范围后,显式或隐式地使用 Set 命令)后,与变量所引用的对象相关联的内存和系统资源才被释放。
再如果不写con.CursorLocation = adUseClient,也没有数据,并且会报错,它会提示行集合不能做为标签.
故我感想:
datagrid太不理想了,因为它的数据是需要绑定的,而不是想MSFlexGrid那样是从数据集里读取的.
























MsFlexGrid它没有datagrid那样娇贵,这不行,那样也不行,只要有个数据集即可.