我正在开发一个Access应用程序(2007),其中调用了一个存储过程(SQL-Server2012),该存储过程应该返回一个简单的结果,即一个包含两条记录的单列表。
在Server Management Studio中执行该过程时,会显示如下结果:
+----------------------------------------------------------+
| One_Sticker |
+----------------------------------------------------------+
| This is the first record of the result |
| This is the second record of the result |
| This is the third and last record of the result |
+----------------------------------------------------------+在我的访问代码中,我有(注意:我知道这是在循环中完成的,但以下内容仅用于调试目的):
Set RS = ADOCmd.Execute
Set blabla = RS.NextRecordset ' Get 1st record
<BP-1> Dummy_Variable = 1
Set blabla = RS.NextRecordset ' Get 2nd record
<BP-2> Dummy_Variable = 1
Set blabla = RS.NextRecordset ' Get 3rd record
<BP-3> Dummy_Variable = 1
Set blabla = RS.NextRecordset ' No more data.
<BP-4> Dummy_Variable = 1表示此行的断点
我在blabla上用手表运行它,看看每一步分配给它的是什么。
当查看BP1、2和3上的手表时,blabla有一个值,而在BP4上是空的。对我来说,这意味着请求的3条记录确实被返回了。问题是blabla中的Fields条目没有任何内容(因此blabla.Fields("One_Sticker").Value是未知的)。如何获取blabla中One_Sticher字段的值?我做错了什么?
提前感谢您的任何有用的建议。
发布于 2017-05-26 01:08:25
在Access中,我通常会:
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT field FROM table WHERE somecriteria ORDER BY field;")
If rs.RecordCount > 0 Then
For x = 1 to 3
blabla = rs!One_Sticker
Debug.Print blabla
rs.MoveNext
Next
End Ifhttps://stackoverflow.com/questions/44176975
复制相似问题