Creating a grid in HTML from a database search I have a little piece of code that is a little bit unoptimized and need some help with optimization in this case.

The procedure is to search in a database using "Conditions/Condicao" and create a grid using tables in HTML with content.  In debug, the following part is taking a long time to complete with 300 results or more.

for (x = 0; x &lt; Campos.Length; x++)
{
    string concat = "";
    for (i = 0; i &lt; 2; i++)
    {
        if (concat != "")
        {
            concat += "," + oDrc[y].ItemArray[1].ToString().Trim().Replace("'", "");
        }
        else
        {
            concat += oDrc[y].ItemArray[0].ToString().Trim().Replace("'", "");
        }
    }
    if (!pkunica)
    {
        concat = "";
        for (i = 0; i &lt; Pks.Length; i++)
        {
            if (concat != "")
            {
                concat += "," + oDrc[y].ItemArray[i].ToString().Trim().Replace("'", "");
            }
            else
            {
                concat += oDrc[y].ItemArray[i].ToString().Trim().Replace("'", "");
            }
        }
    }


I've uploaded the full code to Pastebin.  And about some words, they're in PT-BR.
Use string.Empty instead of "" to indicate an empty string. It conveys your intent without ambiguity (i.e.: nobody will think you forgot to enter something in the string).



When concatenating in a loop, use a StringBuilder.



Use meaningful names. I don't know what concat and oDrc actually mean. Nor pkunica, but that might be a language-issue (I'd encourage you to stick to English-only).