Solved

Truncated text

Posted on 2006-11-28
4
270 Views
Last Modified: 2010-04-07
I have a prayer chain vb.net script that retrieves the request from my MS Access database and displays them in an email.  This has been working fine, but sometimes the full request is not displayed in the email.  I looks like it gets truncated around 40+ characters.  The script is simple and should not be causing this problem. The full text is in the database so that's not the problem.  

Code:

<script language="VB" runat="server">
                   
Sub Page_Load()
                   
     Dim objCmd As OleDbCommand
     Dim objRdr As OleDbDataReader
     Dim objCmd1 As OleDbCommand
     Dim objRdr1 As OleDbDataReader
       Dim sEmail As String
     Dim sName As String
     Dim sBody As String
     Dim strprayer As String
     Dim sPrayerID as String
       Dim sPName As String
     Dim sRequest As String
      
     Dim objConn1 As New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
            dim sql as new System.Text.StringBuilder
            sql.append("SELECT Prayer.* FROM Prayer ")
            '***verify that the requestor is a member
            sql.append("WHERE ((LCase((Prayer.member))='yes') ")
            '***get the critical requests
            sql.append("AND (LCase((Prayer.severity))='critical') ")
            '***get requests that have not been sent
            sql.append("AND ((Prayer.datesent Is Null)) ")
            '***send the requests sometime after 5:00 PM
            sql.append("AND ((DatePart(""h"", Now())>16))) ")
            
            '*** Do weekly mailing if it is Monday and after 5:00 PM
        If Date.Now.DayOfWeek = DayOfWeek.Monday and Date.Now.Hour > 16 Then
                  sql.append("UNION SELECT Prayer.* FROM Prayer ")
                  '***verify that the requestor is a member
                  'sql.append("WHERE ((LCase(Prayer.member))='yes') ")
                  '***verify the request was submitted in the last week
                  'sql.append("AND ((DateDiff(""d"",[Prayer].[datePosted],Now()))<=7) ")
                  '***verify the request has not been sent
                  sql.append("WHERE ([Prayer].[datesent] Is Null) ")
                  '***verify that the request was submitted before 5:00 PM
                  '***this will ensure that if a non-critical request is submitted after 5:00 PM another email will not go out
                  sql.append("AND (DatePart(""h"", Prayer.dateposted) < 17) ")
                  '***verify that the request as not sent within the last day
                  'sql.append("OR ((DateDiff(""d"",[Prayer].[datesent],Now()))>1))")
                  sql.append("ORDER BY dateposted DESC")
            else
                sql.append("ORDER BY dateposted DESC")
            end if

          objCmd1 = New OleDbCommand(sql.tostring, objConn1)
          objConn1.open()
          objRdr1 = objCmd1.ExecuteReader()

            if objRdr1.HasRows then

          While objRdr1.Read()
          sPrayerID = objRdr1("PrayerID")
          sPName = objRdr1("name")
          sRequest = objRdr1("prayerRequest")
              Dim sDate = objRdr1("dateposted")
         strprayer &= "<br />" & "<b>" & "Name: <span class='txtname'>" & sPName & "</span></b>" & _
                              "<dl><dt>" & "Request: " & "</dt><dd>" & sRequest & "</dd></dl>" & _
                             "<div align='center' class='style1'>" & "Date Posted: " & sDate & "</div><hr size=1>"
         '*** Update the Prayer.datesent
         dim objConn2 as New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
         dim objCmd2 as New OleDbCommand("UPDATE Prayer SET datesent=Now() WHERE PrayerID=" + sPrayerID , objConn2)
         objConn2.open()
         objCmd2.ExecuteNonQuery()
         objConn2.close()
         
       End while
          objRdr1.close()
          objConn1.close()            
      
     Dim objMail As New MailMessage
     dim strbody as string
     objMail.Subject="Harvest Prayer Chain"
     Dim objConn As New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
     objCmd = New OleDbCommand("Select fname, email From Members WHERE prayerChain = 'Yes'", objConn)
     objConn.open()
     objRdr = objCmd.ExecuteReader()    
     While objRdr.Read()
     strbody = ""
       sName = ""
       sEmail = objRdr("email")
     sName =objRdr("fname")
      objMail.To = sEmail
     objMail.From = """Prayer Chain"" <webmaster@domain.com>"
     objMail.BodyFormat = MailFormat.HTML
   strbody &= "<html><head><title>" & "</title><style type='text/css'>.style1 {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;}.style2 {font-size: 10px}.style3 {text-transform:capitalize;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #000000; }.standard { font-family: Arial, Helvetica, sans-serif; font-size:14px; color:#333333;}</style></head><body>"
     objMail.Body &= " "
     strbody &= "<table width='658' border='0' cellspacing='0' cellpadding='0'><tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_01.jpg' width='658' height='108' /></td></tr>"
     strbody &= "<tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_02.jpg' width='658' height='81' /></td></tr>"
     strbody &= "<tr><td width='265' ><img src='http://www.domain.com/images/pc/art_03_01_01.jpg' width='265' height='37' /></td>"
     strbody &= "<td width='393' valign='baseline' class='style3' style='background-image:url(http://www.domain.com/images/pc/art_03_01_02.jpg); background-repeat:no-repeat '>Dear " & sName & ",</td></tr>"
     strbody &= "<tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_03_02.jpg' width='658' height='20' /></td></tr>"
     strbody &= "<tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_04.jpg' width='658' height='185' /></td></tr>"
     strbody &= "<tr><td colspan='2'><table width='658' border='0' cellspacing='0' cellpadding='0'><tr><td width='48' style='background-image:url(http://www.domain.com/images/pc/body_01.jpg); background-repeat:repeat-y'></td>"
     strbody &= "<td style='background-image:url(http://www.domain.com/images/pc/body_02.jpg); background-repeat:repeat-y'>" & strprayer & "</td><td width='50' style='background-image:url(http://www.domain.com/images/pc/body_03.jpg); background-repeat:repeat-y'></td></tr></table></td></tr>"
     strbody &= "<tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_06.jpg' width='658' height='121' /></td></tr>"
     strbody &= "<tr><td colspan='2'><img src='http://www.domain.com/images/pc/art_07.jpg' width='658' height='66' border='0' usemap='#Map' /></td></tr></table>"
     strbody &= "<map name='Map' id='Map'><area shape='rect' coords='373,3,419,15' href='http://www.domain.com/Sites/Content/home.aspx' /></map>"
     objMail.Body = strbody & "</body></html>"
    SmtpMail.SmtpServer = "MY IP Address"
     SmtpMail.Send(objMail)              
     
     
       End While
     objRdr.close()
     objConn.close()
       end if
End Sub

</script>
0
Comment
Question by:azyet24
4 Comments
 
LVL 9

Accepted Solution

by:
kraffay earned 250 total points
Comment Utility
True using a StringBuilder instead of concatination.
0
 
LVL 4

Assisted Solution

by:Xeavn
Xeavn earned 250 total points
Comment Utility
I agree with Kraffay, but since you haven't responded in a while, I thought I might try and provide an example of how to use a StringBuilder.

Dim sbOutput As New StringBuilder()
sbOutput.Append("<html><head><title>""&""</title><style type=""text/css"">.style1 {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 12px;}.style2 {font-size: 10px}.style3 {text-transform:capitalize;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; font-weight: bold; color: #000000; }.standard { font-family: Arial, Helvetica, sans-serif; font-size:14px; color:#333333;}</style></head><body>")
sbOutput.Append("<table width=""658"" border=""0"" cellspacing=""0"" cellpadding=""0""><tr><td colspan=""2""><img src=""http://www.domain.com/images/pc/art_01.jpg"" width=""658"" height=""108"" /></td></tr>")

...

objMail.Body = sbOutput.ToString()
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now