标题: 数据返回问题 [打印本页] 作者: mag770t 时间: 2009-2-14 10:26 标题: 数据返回问题 我在ACCESS中写以下的代码:
Dim cTab As Recordset
Dim cTab As Recordset
Set cTab = CurrentDb.OpenRecordset("生产进度查询", 2)
For i = 1 To cTab.RecordCount
在"生产进度查询"中可见数据有超过10000条,但返回的"cTab.RecordCount"值仅为1,请问题各位是什么原因造成的.有关ADO的写法我也是刚在学习,请各位大大帮忙看看,谢谢!在线等待中!作者: tz-chf 时间: 2009-2-14 10:35
你用的是DAO,1就是有值,要movelast一下才知道有多少条
不知道要用循环作什么,可以考虑用do循环作者: mag770t 时间: 2009-2-14 11:38 本帖最后由 mag770t 于 2009-2-14 11:39 编辑
各位大大,我要实现的是将"订单配套表"中的"送成品时间"更新进"生产进度表"中的"成品入库"中,两表以订单编号进行1:1的关联,因两表中数据量都比较大,超10000条,请各位看看如何实现.谢谢! 下面为我写的代码,问题为"cTab.RecordCount"值为1,所以在做"For"循环就不能实现:
Dim cTab As Recordset
Dim nTab As Recordset
Set cTab = CurrentDb.OpenRecordset("生产进度表", 2)
For i = 1 To cTab.RecordCount
cOrdID = cTab("订单编号")
Set nTab = CurrentDb.OpenRecordset("select 订单编号,送成品时间 from 订单配套表 where 订单编号='" & cOrdID & "'", 2)
nData = nTab("送成品时间")
DoCmd.SetWarnings False '屏蔽操作查询提示
' Debug.Print dbsNorthwind.Name
With dbsNorthwind
' Open table-type Recordset and show RecordCount
' property.
Set rstEmployees = .OpenRecordset("Employees")
Debug.Print _
"Table-type recordset from Employees table"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
rstEmployees.Close
' Open dynaset-type Recordset and show RecordCount
' property before populating the Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenDynaset)
Debug.Print "Dynaset-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
' Show the RecordCount property after populating the
' Recordset.
rstEmployees.MoveLast
Debug.Print "Dynaset-type recordset " & _
"from Employees table after MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
rstEmployees.Close
' Open snapshot-type Recordset and show RecordCount
' property before populating the Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenSnapshot)
Debug.Print "Snapshot-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
' Show the RecordCount property after populating the
' Recordset.
rstEmployees.MoveLast
Debug.Print "Snapshot-type recordset " & _
"from Employees table after MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
rstEmployees.Close
' Open forward-only-type Recordset and show
' RecordCount property before populating the
' Recordset.
Set rstEmployees = .OpenRecordset("Employees", _
dbOpenForwardOnly)
Debug.Print "Forward-only-type recordset " & _
"from Employees table before MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
' Show the RecordCount property after calling the
' MoveNext method.
rstEmployees.MoveNext
Debug.Print "Forward-only-type recordset " & _
"from Employees table after MoveNext"
Debug.Print " RecordCount = " & _
rstEmployees.recordcount
rstEmployees.Close
.Close
End With
End Sub
-------------------------------------------------------------
附件中,包含 一个模块 "Mod_recordcount"(就是上面的代码),一个表"employees".作者: ACMAIN_CHM 时间: 2009-2-14 15:42
以下摘自 Microsoft Access 2003 Help
Use the RecordCount property to find out how many records in a Recordset or TableDef object have been accessed. The RecordCount property doesn't indicate how many records are contained in a dynaset-, snapshot-, or forward-only–type Recordset object until all records have been accessed.
4:运行如下代码,完成第3步体提出的要求,完毕!
-------------------------------------------------
Sub my_update()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("select * from qry_1")
Dim m As Long
Dim h As Long
m = DCount("编号", "qry_1") '记录很多的话有些慢,可以参考我在 4 楼给的代码来获取记录数作为for循环的终值
With rs
.MoveFirst
For i = 1 To m
.Edit
h = Nz(.Fields("tbl_a.date"), Empty)
Select Case h '根据一定的条件,向处在同一行的另外一个列写入
Case h
.Fields("tbl_b.date") = Nz(.Fields("tbl_a.date"), Empty)
.Update
End Select
.MoveNext
Next i
End With
rs.Close
Set db = Nothing
Set rs = Nothing
End Sub
-----------------------------------------------------
总之,问题可以描述为:在同一个id所在的行,根据某列的值,更新另外一列的值。