在msflexgrid中执行查询和显示记录时出错 [英] Error in executing query and display record in msflexgrid

查看:79
本文介绍了在msflexgrid中执行查询和显示记录时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ms-access数据库在vb6.0中制作项目,我正在运行查询以在msflexgrid中显示记录.
rs1.Open "select cname, desg, division,dept,ministry From data_detail where country=''" & cmbcontry.Text & "'' GROUP BY cname, desg, division,dept,ministry HAVING Count(*)>1 ", con, adOpenStatic, adLockOptimistic, adOpenKeyset

但它显示以下错误
Item cannot be found in the collection corresponding to the requested name or ordinal
我正在使用组合框选择国家/地区,并在网格中显示其相应的记录.
我使用以下代码

 如果 rs1.RecordCount>  0  然后
      rs1.MoveFirst
      同时(rs1.EOF = 错误)
      trec = trec +  1 
      rs1.MoveNext
      前进
      结束 如果
       trec =  6 
        Mf1.Rows = rs1.RecordCount +  1 
        Mf1.Cols =  6 
        Mf1.Row =  0 
        Mf1.Col =  1 
        Mf1.Text = " 
        Mf1.Row =  0 
        Mf1.Col =  2 
        Mf1.Text = " 
        Mf1.Row =  0 
        Mf1.Col =  3 
        Mf1.Text = " 
        Mf1.Row =  0 
        Mf1.Col =  4 
        Mf1.Text = " 
        Mf1.Row =  0 
        Mf1.Col =  5 
        Mf1.Text = " 
          对于 i =  0  >到 rs1.RecordCount - 1 
            rs1.MoveFirst
            rs1.移动我
            Mf1.Row = i +  1 
            ' 对于rl = 1到rs1.RecordCount 
             ' 对于dup = 2到rs1.RecordCount 
            ' 如果(r1!= dup)然后
            
            Mf1.Col =  1 
            Mf1.Text = rs1.Fields( 9 )//在此我遇到此错误
            Mf1.Col =  2 
            Mf1.Text = rs1.Fields( 10 )
            Mf1.Col =  3 
            Mf1.Text = rs1.Fields( 11 )
            Mf1.Col =  4 
            Mf1.Text = rs1.Fields( 12 )
            Mf1.Col =  5 
            Mf1.Text = rs1.Fields( 13 )
            rs1.MoveNext
         下一步
        对于 i =  1   Mf1.
           对于 j =  0   Mf1. - 1 
                Mf1.Row = i- 1 
                Mf1.Col = j
            下一步
        下一步 


我的目的是要找到相同的记录并将其显示在网格中.
请给我错误的地方打电话给我.
在此先感谢....

解决方案

选中此

项目找不到与所请求名称或顺序相对应的集合
ADODB.Recordset(0x800A0CC1)
在集合中找不到与所请求名称或顺序相对应的项目.
像上面的错误一样,这是一个记录集错误.您尝试从记录集中请求一个不存在的字段.

检查您是何时从记录集中将字段读取到变量中,还是要在网页中显示您是否正确拼写了字段名称以及该字段是否存在于数据库中.

I am making project in vb6.0 using ms-access database, I am running query to display records in msflexgrid.
rs1.Open "select cname, desg, division,dept,ministry From data_detail where country=''" & cmbcontry.Text & "'' GROUP BY cname, desg, division,dept,ministry HAVING Count(*)>1 ", con, adOpenStatic, adLockOptimistic, adOpenKeyset

But it is showing following error
Item cannot be found in the collection corresponding to the requested name or ordinal
I am using combobox to select country and display its corresponding records in grid.
I use the following code

If rs1.RecordCount > 0 Then
      rs1.MoveFirst
      While (rs1.EOF = False)
      trec = trec + 1
      rs1.MoveNext
      Wend
      End If
       trec = 6
        Mf1.Rows = rs1.RecordCount + 1
        Mf1.Cols = 6
        Mf1.Row = 0
        Mf1.Col = 1
        Mf1.Text = "CName"
        Mf1.Row = 0
        Mf1.Col = 2
        Mf1.Text = "Designation"
        Mf1.Row = 0
        Mf1.Col = 3
        Mf1.Text = "Division"
        Mf1.Row = 0
        Mf1.Col = 4
        Mf1.Text = "Department"
        Mf1.Row = 0
        Mf1.Col = 5
        Mf1.Text = "Ministry"
          For i = 0 To rs1.RecordCount - 1
            rs1.MoveFirst
            rs1.Move i
            Mf1.Row = i + 1
            'For rl = 1 To rs1.RecordCount
             '   For dup = 2 To rs1.RecordCount
            'If (r1! = dup) Then
            
            Mf1.Col = 1
            Mf1.Text = rs1.Fields(9)//where i am getting this error
            Mf1.Col = 2
            Mf1.Text = rs1.Fields(10)
            Mf1.Col = 3
            Mf1.Text = rs1.Fields(11)
            Mf1.Col = 4
            Mf1.Text = rs1.Fields(12)
            Mf1.Col = 5
            Mf1.Text = rs1.Fields(13)
            rs1.MoveNext
         Next
        For i = 1 To Mf1.Rows
           For j = 0 To Mf1.Cols - 1
                Mf1.Row = i - 1
                Mf1.Col = j
            Next
        Next


Act my aim is to find same records and display them in grid.
Please tel me where I am wrong.
Thanks in advance....

解决方案

Check this

Item cannot be found in the collection corresponding to the requested name or ordinal
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
This like the error above is a recordset error. You have tried requesting a field from the recordset that does not exist.

Check when you are reading in the field from the recordset into a variable or to display in a web page that you have spelt the field name correctly and that the field exists in the database.


这篇关于在msflexgrid中执行查询和显示记录时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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