Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a way to check if reader has multiple results
Message
De
02/08/2013 14:29:54
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:
01579764
Vues:
36
>>>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);
>                  }
>               }
So you've:
1) spent time discussing this on a message board
2) disrupted your momentum
3) Introduced extra code that will have to be understood and maintained

for a possible sliver of a teensy optimization that might not even be an optimization?

Premature optimization is the devil.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform