如果绑定recordset那么Private Sub Command1_Click() Dim rs As Recordset Set rs = DataGrid1.DataSource MsgBox "当前行为" & rs.AbsolutePosition End Sub
dim a as double dim b as double private sub form_load() rs.open "你的SQL语句",cn,3,1 set datagrid1.datasource=rs if rs.eof =false then a=rs.book end if rs.movenext if rs.eof =false then b=rs.book else b=a end if end sub private sub datagrid1_click() if rs.eof=true then exit sub end if if b=a then c=1 else c=(rs.book-a)/(b-a)+1 end if msgbox str(c) end sub 你试一下应该可以了
3楼的,你往DATAGRID里装50条记录测试一下再回答吧
不行吗?你在窗口上放一个datagrid、adodc和command控件 adodc连接SQLSERVER自带的northwind数据库 然后写如下代码 Private Sub Command1_Click() MsgBox Adodc1.Recordset.AbsolutePosition End SubPrivate Sub Form_Load() Adodc1.RecordSource = "select * from orders" Adodc1.Refresh Set DataGrid1.DataSource = Adodc1.Recordset End Sub用鼠标点到任意一条记录上,然后点击按钮,看看记录号
声明模块级变量a,b数据类型double,把recordset绑定到datagrid中后先rs.movefirst取这时的rs.book放在变量a中,然后rs.movenext再取rs.book放在变量b中,在datagrid_click中代入这个公式c=(rs.book-a)/(b-a),c就是你的总行号
Dim rs As Recordset Set rs = DataGrid1.DataSource
MsgBox "当前行为" & rs.AbsolutePosition
End Sub
dim b as double
private sub form_load()
rs.open "你的SQL语句",cn,3,1
set datagrid1.datasource=rs
if rs.eof =false then
a=rs.book
end if
rs.movenext
if rs.eof =false then
b=rs.book
else
b=a
end if
end sub
private sub datagrid1_click()
if rs.eof=true then
exit sub
end if
if b=a then
c=1
else
c=(rs.book-a)/(b-a)+1
end if
msgbox str(c)
end sub
你试一下应该可以了
adodc连接SQLSERVER自带的northwind数据库
然后写如下代码
Private Sub Command1_Click()
MsgBox Adodc1.Recordset.AbsolutePosition
End SubPrivate Sub Form_Load()
Adodc1.RecordSource = "select * from orders"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1.Recordset
End Sub用鼠标点到任意一条记录上,然后点击按钮,看看记录号