首先Set Grid1.Recordset = rs 应该是 Set Grid1.DataSource = rs 吧 给你我做过的程序代码你试试吧,好用的 记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象 Private Sub Command1_Click() 'strsql 是你的查询语句 你可以order by 排序的字段 'strsql="select xh as 学号 from 表" 这里的学号就是你数据表中字段的标题 strsql="select 字段 from 表" Set Db = New Connection Db.CursorLocation = adUseClient '下面的连接数据字符串你要修改一下 Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False" Set adoPrimaryRS = New Recordset adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic Set DataGrid1.DataSource = adoPrimaryRS end sub
Set Grid1.Recordset = rs 改为这样: Set Grid1.DataSource= rs
MSHFlexGrid,我用的是sqlserver数据库上面是控件名
你的记录源是怎么查出来的,是不是Select * from table1 where ...加了条件?
应该是 Set Grid1.DataSource = rs 吧
给你我做过的程序代码你试试吧,好用的
记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象
Private Sub Command1_Click()
'strsql 是你的查询语句 你可以order by 排序的字段
'strsql="select xh as 学号 from 表" 这里的学号就是你数据表中字段的标题
strsql="select 字段 from 表"
Set Db = New Connection
Db.CursorLocation = adUseClient
'下面的连接数据字符串你要修改一下
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = adoPrimaryRS
end sub
改为这样:
Set Grid1.DataSource= rs
rs记录集有多少记录呢?
看看 rs.count 的值