格式化我发送的电子邮件时遇到困难。我需要的所有数据都被返回,但有些vbNewLines无效。
这是代码。请注意,顶部的大块工作正常,包括& vbNewLine& vbNewLine最后的双重空间。
Dim arErrors As Array = Array.CreateInstance(GetType(String), 1000)
<<SQL select>>
odbcCmd = New OdbcCommand(strSQL.ToString, odbcConn)
odbcCmd.CommandTimeout = 100000
Rs = odbcCmd.ExecuteReader()
Do While Rs.Read
If Len(Trim(Rs.Item("Cu_Rep_Id").ToString)) = 6 Then
odbcCmd2 = New OdbcCommand(<<SQL Select>>)
odbcCmd2.CommandTimeout = 100000
Rs2 = odbcCmd2.ExecuteReader()
If Rs2.HasRows Then
If Trim(Rs2.Item("Rep_Job_Cd").ToString).IndexOf("SMIC REP, SMIC - WAVERLY, SALES REP - WAVERLY, SALES REP - MADISON") = -1 Then
If CType(Rs2.Item("Rep_Term_Dt"), Date) < Now() Then
arErrors.SetValue("Difference for Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " (Rep terminated on " & Rs2.Item("Rep_Term_Dt").ToString & ")", intMax)
intMax = intMax + 1
Else
arErrors.SetValue("Difference for Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for SMIC Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for Unknown Rep: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Rs2.Close()
ElseIf Len(Trim(Rs.Item("Cu_Rep_Id").ToString)) = 8 Then
odbcCmd2 = New OdbcCommand(<<SQL Select>>)
odbcCmd2.CommandTimeout = 100000
Rs2 = odbcCmd2.ExecuteReader()
If Rs2.HasRows Then
If CType(Rs2.Item("Prog_End_Dt"), Date) < Now() Then
arErrors.SetValue("Difference for CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " CU Status: " & Rs2.Item("Cu_Status").ToString & " (CU terminated on " & Rs2.Item("Prog_End_Dt").ToString & ")", intMax)
intMax = intMax + 1
Else
arErrors.SetValue("Difference for CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2) & " CU Status: " & Rs2.Item("Cu_Status").ToString, intMax)
intMax = intMax + 1
End If
Else
arErrors.SetValue("Difference for Unknown CU: " & Trim(Rs.Item("Cu_Rep_Id").ToString) & " Navigator: " & FormatCurrency(CType(Rs.Item("Data_Vl_Nr"), Decimal), 2) & " TruComp: " & FormatCurrency(CType(Rs.Item("Data_Value"), Decimal), 2) & " Difference: " & FormatCurrency(CType(Rs.Item("Diff"), Decimal), 2), intMax)
intMax = intMax + 1
End If
Rs2.Close()
Else
If Trim(Rs.Item("Cu_Rep_Id").ToString) <> "" Then
arErrors.SetValue("Invalid Ps_Nr or Contr_Nr: " & Trim(Rs.Item("Cu_Rep_Id").ToString), intMax)
intMax = intMax + 1
End If
End If
Loop
Rs.Close()
If Dts.Variables("DeletedCount").Value <> "0" Then
strBody = strBody & Dts.Variables("DeletedCount").Value & " records were removed from TruComp_Detail prior to load." & vbNewLine & vbNewLine
End If
再次,上面的vbNewLine&amp; vbNewLine完美地作为双重空间。下面是让我适合的令人讨厌的循环。返回数据,但&amp; vbNewLine不起作用。
intCount = 0
Do While intCount < intMax
strBody = strBody & arErrors.GetValue(intCount).ToString & vbNewLine
intCount = intCount + 1
Loop
strBody = strBody & "Process complete."
答案 0 :(得分:5)
电子邮件使用HTML格式,因此您希望改为使用<br/>
。
Do While intCount < intMax
strBody = strBody & arErrors.GetValue(intCount).ToString & "<br/>"
intCount = intCount + 1
Loop
答案 1 :(得分:0)
我最近遇到了同样的问题。我通过使用StringBuilder和Append(System.Environment.Newline)方法而不是常规字符串连接来解决它。
我不知道它是否有任何区别,但我使用的是C#。
在我的应用程序中,切换到HTML格式是不可行的,因为从应用程序发送了许多其他电子邮件,所有文本格式化。