我有一个存储过程返回的153个电子邮件地址(此数字可能有所不同),我加载到SqlDataReader
(r
)。我的电子邮件中继服务器一次最多可以发送50个电子邮件地址。如何创建X个组,以便我不会超出读者的限制?
Dim myCommand As New SqlCommand("sproc_Get_Emails", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add(New SqlParameter("@List_Type", SqlDbType.Char))
myCommand.Parameters("@List_Type").Value = priority
Dim r As SqlDataReader
myConnection.Open()
r = myCommand.ExecuteReader()
我对如何做到这一点一片空白。我的想法就是这个......
'get count of all email addresses and divide by 50, then send each in 50 record batches???
Dim email_count As Integer = 0
'get count and divide by 50
email_count = r.RecordsAffected
Dim list_size As Double = email_count / 50
非常感谢任何帮助。
答案 0 :(得分:1)
基本方法是使用计数器变量:
Dim count as Integer
Dim address as String
While r.Read
address = address + r.Field("email") + ";"
count = count + 1
If count = 50 Then
' send
count = 0
address = ""
End If
End While
' see if there are any remaining addresses
If Not String.IsNullOrEmpty(address) Then
' send
End If
其他方式:
Skip
和Take
来有效地执行相同的操作