Hi

I am using StringBuilder to compose an email. The body of email consists of
a table for which data has to be taken fron SQL Server.

I use appen method to add text to the StringBuilder variable. When I am
finished I call ToString function to get the string.

The problem is that many times, it changes the text I appended to it. Like
when I append

<TH vAlign=top noWrap width=30>ABC<BR>10<BR>5<br>05</TH>

it some time changes that to
<TH vAlign=top noWrap width=30>Tue<BR>10<BR>5< br>05</TH>

some time it does this with other HTML attribute (mostly with < >). This
happens occasionaly. Sometime it works fine and sometime not.

I tried using the String instead of StringBuilder but the problem is still
there.

Please help me.

In addition to above by ramata

ramata
Thu May 12 04:53:01 CDT 2005

Once it changed:

<TH vAlign=top noWrap width=30><FONT face=Arial size=2 color="#ffffff"
>ABC<BR>6<BR>5<BR>05</FONT></TH>

to

<TH vAlign=top noWrap width=30><FONT face=Arial size=2 r="#ffffff"
colo>ABC<BR>6<BR>5<BR>05</FONT></TH>

strange behaviour

Thanks in advance

"ramata" wrote:

> Hi
>
> I am using StringBuilder to compose an email. The body of email consists of
> a table for which data has to be taken fron SQL Server.
>
> I use appen method to add text to the StringBuilder variable. When I am
> finished I call ToString function to get the string.
>
> The problem is that many times, it changes the text I appended to it. Like
> when I append
>
> <TH vAlign=top noWrap width=30>ABC<BR>10<BR>5<br>05</TH>
>
> it some time changes that to
> <TH vAlign=top noWrap width=30>Tue<BR>10<BR>5< br>05</TH>
>
> some time it does this with other HTML attribute (mostly with < >). This
> happens occasionaly. Sometime it works fine and sometime not.
>
> I tried using the String instead of StringBuilder but the problem is still
> there.
>
> Please help me.
>

RE: Strange bug in StringBuilder by NoSpamMgbworld

NoSpamMgbworld
Thu May 12 07:31:02 CDT 2005

1. What version of the Framework?
2. What is the specific code you are using?

The StringBuilder is a character array. I am not sure how it would change
ABC to Tue (change char values), but I could see a possibility of changing
the order of letters. If it is changing char values, I would look at encoding
first. The order of letters sounds like a genuine bug.

As you have quotes, make sure they are properly escaped.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"ramata" wrote:

> Hi
>
> I am using StringBuilder to compose an email. The body of email consists of
> a table for which data has to be taken fron SQL Server.
>
> I use appen method to add text to the StringBuilder variable. When I am
> finished I call ToString function to get the string.
>
> The problem is that many times, it changes the text I appended to it. Like
> when I append
>
> <TH vAlign=top noWrap width=30>ABC<BR>10<BR>5<br>05</TH>
>
> it some time changes that to
> <TH vAlign=top noWrap width=30>Tue<BR>10<BR>5< br>05</TH>
>
> some time it does this with other HTML attribute (mostly with < >). This
> happens occasionaly. Sometime it works fine and sometime not.
>
> I tried using the String instead of StringBuilder but the problem is still
> there.
>
> Please help me.
>

RE: Strange bug in StringBuilder by ramata

ramata
Thu May 12 07:52:01 CDT 2005

Sorry for my one mistake. The pattern ABC was replaced by me. The project I
am working on is confidential, so I tried to change Tue to ABC, but forget in
other place.

But, StringBuilder did changed
<FONT face=Arial size=2 color="#ffffff">

to

<FONT face=Arial size=2 r="#ffffff" colo>

I am using VStudio 2003 Vb.net and building for .net 1.1

Re: Strange bug in StringBuilder by Jon

Jon
Thu May 12 15:38:03 CDT 2005

ramata <ramata@discussions.microsoft.com> wrote:
> I am using StringBuilder to compose an email. The body of email consists of
> a table for which data has to be taken fron SQL Server.
>
> I use appen method to add text to the StringBuilder variable. When I am
> finished I call ToString function to get the string.
>
> The problem is that many times, it changes the text I appended to it.

I find that very hard to believe.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Re: Strange bug in StringBuilder by Dick

Dick
Fri May 13 00:13:48 CDT 2005

Code?

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.



code by ramata

ramata
Fri May 13 01:26:03 CDT 2005

The code is Vb.Net code. Basically two procedures. One composes email and
other sends it. This can be put in any Vb.net class and calling SendEmail()

Public Sub GetEmailBody(ByRef strHTMLMessage As StringBuilder)

Dim strQuery As String
Dim Adodc1 As ADODB.Recordset
strHTMLMessage.Remove(0, strHTMLMessage.Length)

' create HTML message
strHTMLMessage.Append("<html><head><title>My page</title> " _
& "<style type=""text/css"">th {color:
#ffffff;font: bold 12px arial} td.b {color: #ffffff;font: bold 12px arial}
</style></head><body>" _
& "<table align=center border=1 cellspacing=0
cellpadding=1 style='border-collapse: collapse' bordercolor=#777777>" _
& "<tr bgcolor=#ff0000>" _
& "<th nowrap valign=top align=left
width=200>col1</th>" _
& "<th valign=top>col2</th>" _
& "<th nowrap valign=top>col3<br>one<br>two</th>" _

Adodc1 = New ADODB.Recordset


Dim strQuery As String = "SELECT * FROM sample"

' conn is global Adodb.Connection
Adodc1.Open(strQuery, conn)

If Not Adodc1.EOF Then

Do Until Adodc1.EOF

strHTMLMessage.Append(vbCrLf & "<tr bgcolor=#ffcccc>")

strHTMLMessage.Append("<td nowrap align=left>" &
tmpPlay.StationName & "</td><td nowrap align=left>" &
tmpPlay.PresentationRegion & "</td>")

loop

strHTMLMessage.Append("</tr>")

Next

' end of table
strHTMLMessage.Append("</table>")
strHTMLMessage.Append("</body></html>")

End Sub

Public Sub SendEmail()

Dim strBody As New StringBuilder

Dim mailmsg As CDO.Message
Dim Conf As CDO.Configuration
mailmsg = New CDO.Message
mailmsg.Configuration.Load(CDO.CdoConfigSource.cdoIIS)

eMailFrom = "abc@yahoo.com"


GetEmailBody(strBody)
eMailSubject = "testing"

With mailmsg
.From = eMailFrom
.Subject = eMailSubject
.To = recp(i).email
.HTMLBody = strBody.ToString
.Send()
End With

End Sub

Re: code by Jon

Jon
Fri May 13 01:33:46 CDT 2005

ramata <ramata@discussions.microsoft.com> wrote:
> The code is Vb.Net code.

<snip>

See http://www.pobox.com/~skeet/csharp/incomplete.html

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too