ADODB RecordSet转换为字符串变量VBA [英] ADODB RecordSet to string variable VBA

查看:316
本文介绍了ADODB RecordSet转换为字符串变量VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关ADODB记录集的快速问题。我想从记录集中提取查询结果并将其设置为字符串变量:

Quick question about ADODB recordset. I want to extract a query result from a recordset and set it to a string variable:

query = "SELECT Value1 FROM Table"
RS = New ADODB.Recordset
RS.Open(query,Conn)

查询总是要返回3个值。我想将这三个值分配给一个变量。 RS.GetString返回定界的查询结果选项卡,但我希望能够遍历此集合并将每行结果分配给它自己的变量。有任何想法吗?

The query is always going to return 3 values. I want take to assign these three values to a variable. RS.GetString returns the query results tab delimited, but I want to be able to iterate through this set and assign each row result to its own variable. Any ideas? Thanks in advance!

推荐答案

您可以通过记录集按名称访问表列。

You can access the tables columns by name through the recordset.

Dim strValue As String
strValue = rs.Fields("ColumnNameHere").Value

关于循环记录集

Do While rs.EOF = False

    strValue = rs.Fields("ColumnNameHere").Value
    msgbox (strValue)

rs.MoveNext
Loop

如果您只是在学习循环。在某些时候,您将需要了解 rs.MoveFirst

And if you are just learning looping. You'll at some point need to learn about rs.MoveFirst

由于某种原因想要再次遍历它,则需要先移回记录集的开头,然后才能再次循环它。

Once you have been through your recordset and you want to go through it again for some reason you will need to move back to the beginning of the recordset before you can loop it again.

记录集也具有 rs.Find rs.Filter rs.Sort

很多东西。

这篇关于ADODB RecordSet转换为字符串变量VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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