Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Truncated text

Posted on 2006-11-28
4
Medium Priority
?
286 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 1000 total points
ID: 18030549
True using a StringBuilder instead of concatination.
0
 
LVL 4

Assisted Solution

by:Xeavn
Xeavn earned 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

916 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