Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a way to check if reader has multiple results
Message
 
 
À
02/08/2013 12:31:10
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01579688
Message ID:
01579753
Vues:
39
>>Do you know if there is such a property or there is another way to handle the above efficiently?
>>
>>Thanks in advance.
>
>Use StringBuilder. The teeny tiny efficiency you think you will gain (and I don't think there will be any) is not worth adding extra code.

In 99% of the cases we only use a single result. GetFormattedReturn method returns the string with the results formatted as XML or other formats. So, in 99% of cases I will be instantiating this StringBuilder with may be long string passing as parameter. I think it's better to not do it for these 99% of the cases when it's not used.

Here is my current method code:
 using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
               {
                  Int32 recordCount = 0;
                  this.lastExecution.FormattedReturn = GetFormattedReturn(sqlDataReader, returnType, out recordCount);
                  this.lastExecution.RowsReturned = recordCount;
                  // Generate the return string (STR/XML/XM2), if applicable
                  if (0 == recordCount && ReturnType.STR == returnType && String.IsNullOrWhiteSpace(this.lastExecution.FormattedReturn))
                  {
                     this.lastExecution.StatusCode = 1;
                     this.lastExecution.FormattedReturn = "DONE";
                  }
                  while (sqlDataReader.NextResult())
                  {
                     this.lastExecution.FormattedReturn = this.lastExecution.FormattedReturn + Environment.NewLine + GetFormattedReturn(sqlDataReader, returnType, out recordCount);
                  }
               }
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform