Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Truncated text

Posted on 2006-11-28
4
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 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