>>>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.