Solved

Truncated text

Posted on 2006-11-28
4
272 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
ID: 18030549
True using a StringBuilder instead of concatination.
0
 
LVL 4

Assisted Solution

by:Xeavn
Xeavn earned 250 total points
ID: 18069819
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Handle null when using linq in this line 1 26
Class object 2 26
Syntax error 9 45
Split in Javascript 5 30
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

17 Experts available now in Live!

Get 1:1 Help Now