我知道这是一个初学者问题,但是从VB.NET和VB6来回切换让我感到困惑。我正在尝试从我创建的Access表中检索电子邮件地址,并将它们存储在一个字符串中供以后使用。这是我到目前为止所拥有的;
Private Sub cmdSubmit_Click()
Dim MyConn As New ADODB.Connection
Dim MyRecSet1 As New ADODB.Recordset
Dim EmailList As String
Set MyConn = New ADODB.Connection
EmailList = ""
MyConn.ConnectionString = "Some String"
MyConn.Open
Set MyRecSet1 = MyConn.Execute("SELECT DISTRIBUTION_LIST.[EMAIL_ADDRESS] FROM DISTRIBUTION_LIST")
EmailList = MyRecSet1!EMAIL_ADDRESS
MyConn.Close
lblHeadDesc.Caption = EmailList
End Sub
我可以获得1个电子邮件地址,但我想全部收到。
答案 0 :(得分:1)
阅读时,您可以循环获取所有行,直到设置了EOF:
Do While Not MyRecSet1.EOF
EmailAddress = MyRecSet1!EMAIL_ADDRESS
'Do something with EmailAddress
Loop
答案 1 :(得分:0)
我可能误解了你的问题,但听起来你想要Recordset的GetString()
方法:
With MyConn.Execute("SELECT EMAIL_ADDRESS FROM DISTRIBUTION_LIST", , adCmdText)
EmailList = .GetString(adClipString, , , vbNewLine)
.Close
End With
MsgBox EmailList
答案 2 :(得分:0)
For i = LBound(VarList, 2) To UBound(VarList, 2)
For j = LBound(VarList, 1) To UBound(VarList, 1)
EmailList = EmailList + VarList(j, i) & ", "
Next j
Next i
获取所有电子邮件地址。
感谢OverMind的帮助。