您的位置:程序门 -> vb -> 基础类



sql中如何返回当前行


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


sql中如何返回当前行
发表于:2007-06-03 10:58:11 楼主
我需要返回查询结果在记录集中所在位置,有一个笨办法,但是效率太低,有什么好的解决办法没

笨办法

dim   curnum   as   integer

rs.open "select   *   from   data_info ",conn,1,3
if   rs.recordcount <> 0   then
do   while   not   rs.eof
curnum=curnum+1
if   rs( "id ")= "dt070501137 "   then
exit   do
end   if
loop
end   if
rs.close

如果记录多的话,速度就爆慢,有什么更好的办法没
发表于:2007-06-03 12:11:261楼 得分:0
没人回答这个问题么???

应该不是很难吧~~~~~
发表于:2007-06-03 12:31:492楼 得分:0
where  

或者在   recordset   使用   seek()/find()   函数

请参考   msdn
发表于:2007-06-03 13:07:243楼 得分:0
不行啊,老兄
发表于:2007-06-03 14:32:254楼 得分:0
select   *   from   data_info   where   id= 'dt070501137 '
发表于:2007-06-03 15:35:205楼 得分:0
数据库允许的话在加个自增字段吧,那就可以根据select   count(自增字段)   from   表   where   自增字段 <(select   自增字段   from   表   where   id= 'dt070501137 ')了
发表于:2007-06-03 16:23:136楼 得分:0
to   cathysun118(斯年)
你可能理解错误题目了,我不是要查询,只是要返回这条记录在整个数据集中的第几行

to   danielinbiti(金)  
表中是有一个字段为自增字段,但是这个字段并不能代表所在记录行,中间可能有数据被删除的,所以并不连贯
发表于:2007-06-03 16:35:537楼 得分:0
ado的absoluteposition属性。
发表于:2007-06-03 23:37:358楼 得分:0
'try   it!

sub   adofindrecord()

      dim   cnn   as   new   adodb.connection
      dim   rst   as   new   adodb.recordset

      '   open   the   connection
      cnn.open   "provider=microsoft.jet.oledb.4.0; "   &   _
            "data   source=.\northwind.mdb; "     'your   source   database   path

      '   open   the   recordset
      rst.open   "customers ",   cnn,   adopenkeyset,   adlockoptimistic
     
      '   print   the   absolute   position
      debug.print   "rst.absoluteposition_1= ";rst.absoluteposition

      '   find   the   first   customer   whose   country   is   usa
      rst.find   "id= 'dt070501137 ' "
    debug.print   "rst.absoluteposition_2= ";rst.absoluteposition
      '   print   the   customer   id 's   of   all   customers   in   the   usa
      do   until   rst.eof
            rst.find   "id= 'dt070501137 ' ",1
            debug.print   "rst.absoluteposition_3= ";rst.absoluteposition
      loop

      '   close   the   recordset
      rst.close
end   sub


快速检索

最新资讯
热门点击