簡體   English   中英

從datareader創建asp.net電子郵件批次

[英]Create asp.net batches of emails from datareader

我從存儲過程返回了153個電子郵件地址(此數字可能有所不同),並將其加載到SqlDataReaderr )中。 我的電子郵件中繼服務器一次最多可以發送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

任何幫助將非常感激。

基本方法是使用計數器變量:

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

其他方法:

  • 使用Linq擴展程序將電子郵件分為50組,然后循環遍歷
  • 使用Ling SkipTake in a loop有效地完成同一件事

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM