Web Forms :: Use Stringbuilder When Concatenating More Than 2 Strings - Performance?
Jul 2, 2010
I have been led to believe that the performance benefits of using StringBuilder over normal concatenation means that you should always use stringbuilder when concatenating more than 2 strings. However when I test them this does not seem to be the case. Take these 2 methods
public void TestMethod5()
{
for (int i = 0; i < 1000; i++)
{
string t = string.Empty;
t = "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd" + "dddddddd"; ;
}
}
public void TestMethod6()
{
for (int i = 0; i < 1000; i++)
{
StringBuilder sb = new StringBuilder();
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
sb.Append("dddddddd");
string t = string.Empty;
t = sb.ToString();
}
}
TestMethod5 takes 0.03 milliseconds so complete but TestMethod6 takes 1.43 milliseconds What is going on?
View 3 Replies
Similar Messages:
May 28, 2010
I am trying to find the best way to concatenate two strings and set the result to the text property of a label during design time.Here is what is not working:
I have Text="<%$Resources:labels, btnLinkNoText%>" and Text='<%# Bind("ProductID") %>'
I want Text="<%$Resources:labels, btnLinkNoText%>" + Text='<%# Bind("ProductID") %>'
View 3 Replies
Mar 14, 2011
I'm having a strange behavior in my .aspx page. I'm internationalizing some pages, but as I want to keep only entities or value object in my resource I want to have a key-value like:
(pt-br)
CITY - Cidade
STATE - Estado
But when I list the entities, I want to put the " : " at end. Like:
<asp:Label ID="LabelCity" runat="server" Text="<%$ Resources:Localizacao, CITY %>:"></asp:Label>
But, if I put the " : " after the resource in text property, the page only shows " : ".
My simple solution is put after all definition of label, but I think this too wrong:
<asp:Label ID="LabelCity" runat="server" Text="<%$ Resources:Localizacao, CITY %>"></asp:Label>:
View 2 Replies
Sep 20, 2010
I have developed a website in asp.net framework 2 . This website is being hosted in two different servers without any change in code. My issue is about the performance of these 2 sites. One website is taking much time for inserting datas to the DB (SQL server 2005). 2 websites are having different DB server.
I think the issue is for the DB server. How can we rectify the DB performance while insertion and Is there any other cause for this permance issue?
View 1 Replies
Apr 29, 2010
I am not sure if this is the right forum. I can not find a forum for LINQ.
I am working on an application using LINQ. Application performance is not up to par and my tests show that it is LINQ queries that are slow. I was wondering if anybody can recommend where I can find an article about optimizing LINQ performance maybe by compilation or other methods.
View 1 Replies
Dec 6, 2010
i have the below query where MessageText column is of ntext datatype..whe n i run the below query it is giving me the below error. Error :The data types ntext and varchar are incompatible in the add operator.
select li.LookUpPageInfoId,
li.PageMessageID,
li.PathMessageID,
li.IsActive,
m.MessageID,
(select messagetext from messages where messageid=pagemessageid and channelid=m.ChannelID)+'/'+
m.MessageText as TotalText,
m.ChannelID
from
LookUpPageInfo as li left outer join
Messages as m on m.MessageID=li.PathMessageID and li.IsActive=1
Can some one suggest me how to concatenate the ntext column....but the above works good if the column MessageText is of nvarchar(max) datatype.
View 2 Replies
Jan 19, 2011
I am writing an SQL query in which that I will need to perform a sub select on a table, which will usually return multiple rows. I need to be able to join together the results of a certain field from all the rows into one field to output. Is this possible, and how?
For example, if the SQL query returns
id | field
1 | test1
2 | test2
3 | test3
I need the outputted field to be "test1 test2 test3".
View 4 Replies
Apr 13, 2010
I have a problem where I would like to get a comma-separated list of items from a couple of tables as part of a set of results. All the searching I've done so far has produced results for dealing with one or two tables. I have four, and can't get my head around how to adapt the sql to deal with it.
I have the following layout:
*Table_Castings*
+---- CastingID {PK}
| MouldID
| SerialNo
| CastRef
| MeltCode
| Signature
|
|
| *Table_CastCertificates* *Table_Certificates*
| CertificateID {PK} ----------- CertificateID {PK}
+---- CastingID {PK} Description
FileID -----------------+
|
|
*Table_CertificateFiles* |
FileID {PK} -------------+
FullLocation
The results I would like include the following columns:
CastingID, MouldID, SerialNo, CastRef, MeltCode, [Certificates],
Where Certificates is a comma separated list of Description + " " + FullLocation records. (What I'll actually do is add http:// and other html codes to make FullLocation a hyperlink, but I can do that.)
Some SQL I've already got is this:
DECLARE @str VARCHAR(500)
SELECT @str = COALESCE(@str + ', ','') + '<a href="http://' + Table_CertificateFiles.FullLocation + '">' + Table_Certificates.Description + '</a>'
FROM Table_CastCertificates INNER JOIN
Table_Certificates ON Table_CastCertificates.CertificateID = Table_Certificates.CertificateID INNER JOIN
Table_CertificateFiles ON Table_CastCertificates.FileID = Table_CertificateFiles.FileID
WHERE (CastingID = 45)
SELECT output = @str
This actually gives all records in the for the specific casting, but I keep getting an error at the "=" in @str = COALESCE when I try joining it to another query to get each casting.
View 3 Replies
May 11, 2010
I need to concatenate several columns of a table into a single value, then show that value in an asp dropdownlist. The SQL code I'm issuing is as follows:
SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo
FROM Users
WHERE (CustomerNum = @CustomerNum)
ORDER BY UserName
I then set 'UserInfo' as the text field in the dropdownlist.This generally works, except occasionally one of the columns in the database is null (for example, UserState). When that happens, the entire concatenation is null, and I get an empty entry in the dropdownlist.
Is there something in SQLServer that will allow me to ignore those NULL results, or will I have to code something up in the DataBind event?
View 6 Replies
Jun 2, 2010
Trying to localize text in ASP.NET labels... want to add a ':' after the localized text. I could just add the ':' to the localized text in the resource file, but that seems silly... there should be an easy way to do this.
<asp:Label id="RoleTypeLabel" runat="server" Text='<%$ Resources: GS3, RoleTypeLabel %>:' AssociatedControlID="RoleTypeDropDown"></asp:Label>
(note the ':' at the end of Text='...')
Of course, this doesn't work... and neither does anything I can think of to concatenate a ':' onto the end of the localized text.
View 3 Replies
Jun 22, 2010
adding data from more than one columns of a table in drop down list but not concatening them.
Like a table having columns Station_1 , Station_2 , Station_3. All these columns having place names.
Now I want to list the distinct station/place names from each columns Station_1, Station_2 and Station_3 in my drop down list.
How to do this I serched everywhere in but not found the solution..
View 4 Replies
May 24, 2012
I am converting HTML to Pdf using StringBuilder .. added one image using
Doc theDoc = new Doc();
System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();
sbHtml.Append("<html>");
sbHtml.Append("<body>");
sbHtml.Append("</table></td> <td width='406' height='104'><div align='right'><img src='~/images/logo.jpg'
[Code] ....
Here image is not displaying in PDF ....
View 1 Replies
Mar 20, 2011
I am creating a service oriented application where trying to have everything using services....however there is something I am not sure of , I am having a page that calls the database at the page load...so what would be better and faster?? to call database in pageload , or to call wcf service from javascript during javascript load ??btw , I am using a repeater in the page , but I have created somekind of an engine to create the suitable html so...I'll be creating the repeaters html using the wcf and resend it back to the page If I am using a wcf service at the start.
View 1 Replies
Jan 18, 2010
if i change the code and put checkbox between the <td> tag. when i click the save button, how can i check the ticked checkbox and get the value of the CHECKBOX_1 in cs?
[Code]....
View 5 Replies
Feb 23, 2010
how can i do the split function like excel in stringBuilder?
View 4 Replies
Jan 19, 2010
i can get the checkbox value from the stringBuilder by request.form["field_id"].toString(), but how can i make the checkbox checked property to checked using C#.
[Code]....
View 4 Replies
Dec 22, 2010
I want to create new string or stringbuilder based on condition; Example . I am updating a count variable "i"; if i = 100, i need to create a string or stringbuilder; if else i = 200 i need to create a new string or stringbuilder; if else i = 300 i need to create a new string or stringbuilder; and so on how i can achive this?
View 8 Replies
Sep 23, 2012
I use this code in my page
protected void Button1_Click(object sender, EventArgs e) {
string url = "page2.aspx";
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.open('");
sb.Append(url);
sb.Append("');");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(),
"script", sb.ToString());
}
but this error occur
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0246: The type or namespace name 'StringBuilder' could not be found (are you missing a using directive or an assembly reference?)Source Error:
Line 145: {
Line 146: string url = "page2.aspx";
Line 147: StringBuilder sb = new StringBuilder();
Line 148: sb.Append("<script type = 'text/javascript'>");
Line 149: sb.Append("window.open('");
how i can solve it?
View 1 Replies
Nov 6, 2010
i want make html table in format so i used follwing code but it just print tags(rather than analyze them as html and give appropriate output )
[Code]....
Output got when tried to use TransList.ToString() output got was
<html> <head> </head><body><table><tr><td>1</td><td>11/24/2010 12:00:00 AM</td><td>Paypal</td><td>30</td></tr><tr><td>2</td><td>11/24/2010 12:00:00 AM</td><td>Paypal</td><td>300</td></tr><tr><td>3</td><td>12/10/2010 12:00:00 AM</td><td>Paypal</td><td>240</td></tr></table></body></html>
View 4 Replies
Jan 27, 2010
I am getting the following error with my GridView using StringBuilder/StringWriter: MyGridView of type 'GridView' must be placed inside a form tag with runat=server.
StringBuilder SB = new StringBuilder();
StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
MyGridView.RenderControl(htmlTW); //error here
string s = SW.ToString();
I am also using a MasterPage, which I believe has a lot to do with why I am getting this error. Is there a work around?
View 1 Replies
Mar 19, 2010
i want to display the values in repeator which i captured using string builder.
i captured the values using "Append" key word,
View 3 Replies
Oct 19, 2010
String is immutable and StringBuilder is mutable. So if I change the value of a string a new memory created with the new value, whereas in StringBuilder it updates its memory location rather than creating a new memory location. So for large concatenation stringBuilders are preffered. But when I create a new String object, a fixed memory is created. And any changes will update its memory location, rather than creating a new memory location.
For e.g.
String s = new String();
s = String.Empty;
for ( int i=0;i<100; i++)
{
//s = s + "test" + i.ToString();
s =string.Concat(s, "test" + i.ToString()); ///This is effecient compared to previous step
}
Now instead of String class I will use a StringBuilder class.
StringBuilder s = new StringBuilder(String.Empty);
for ( int i=0;i<100; i++)
{
//s = s + "test" + i.ToString();
s.append( "test" + i.ToString());
}
View 13 Replies
Dec 2, 2010
Is StringBuilder a datatype?
View 9 Replies
Jan 22, 2010
I've a string builder, and I need to convert it to a string, and then trim any commas if there are any there (I need to get rid of them because I'm building an sql query).
Here's what I'm doing:
myStringBuilder.ToString().TrimEnd(',');
Why isn't this working??? It's not trimming any commas at the end!
I'm using c# :)
View 9 Replies
Jul 9, 2010
I have a message on one and I'm sending that message to another using a Session. The problem is the message come out on one line, please code
[Code]....
Output: --- Original Message ---message for the user.
Output should be:
Original Message
message from the user. How do get the info on two lines?
View 10 Replies