在vb6 ..中从数据库中找到最小数字时出错? [英] Error during finding smallest number from database in vb6..?

查看:55
本文介绍了在vb6 ..中从数据库中找到最小数字时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用此代码时,它显示错误为"EOF,如果需要移动下一个记录集,并且如果我请求for循环调用"while not rs.EOF",则循环不执行. 此代码中有什么错误.
我想使用循环(或任何简单的方法,如果您知道的话)从访问数据库中找到最小的数字
如果您还有其他方法可以从数据库中找到最小的数字,请告诉我...?

When i used this code it shows error that is "EOF if required for move next record set and if i call "while not rs.EOF" on begging of for loop then loop is not execute
what is error in this code.
I want to find smallest number from access database using loop (OR any simple method if you know)
if you have any other method to find smallest number from database then please tell me...?

Dim constr
constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\xyz.mdb;Persist Security Info=False"
Dim con As New ADODB.Connection
         con.Open constr
         Dim rs As New ADODB.Recordset
         rs.Open "Select * from xyz where abc ='A'", con, adOpenDynamic, adLockOptimistic

Dim Aray(1 To 10) As Integer
Dim sn As Integer
Dim i
Dim a
For i = 1 To 10
Aray(i) = rs("xyz")
rs.movenext
Next
sn = Aray(1)
For a = 1 To 10
If Aray(a) < sn Then sn = Aray(a)
Next
MsgBox "The smalles number is: " & sn, vbInformation
rs. closed
con.closed

推荐答案

不需要使用数组.我假设这是一个家庭作业问题,因为您明确地想找到如何使用循环来定位最小的数字...您可以使用min()函数直接从数据库中获取它.

这是有关如何执行此操作的代码段-您将需要根据需要进行填充.

There''s no need for you to use an array. I assume this is a homework question, since you explicitly want to find out how to locate the smallest number using a loop... You can get it directly from the database by using the min() function.

Here''s a code snippet for how to go about it - you will need to pad it out as required.

' Get the initial value
sn = rs("xyz")
rs.movenext

' While not eof, cycle through and check the rest
do while not rs.eof
  if sn < rs("xyz") then
    ' It's smaller, better record that value instead
    sn = rs("xyz")
  end if
  
  ' Move to next record
  rs.movenext
loop


这篇关于在vb6 ..中从数据库中找到最小数字时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆