I have a DataReader and a StringBuilder (C#.NET) used in the following way;
while (reader.Read())
{
sb.AppendFormat("{0},{1},{2},",reader["Col1"], reader["Col2"], reader["Col3"]);
}
Which works great for my use, but when a row is null I need it to return “null”, instead of just “”. What would be a good way of accomplishing that?
Suggestions are very appreciated
Try:
Alternatively, if you’re going to be using this repeatedly, this is probably an ideal candidate for a tightly scoped Extension Method, for example:
So you could then write:
Which would definately make things tidier if you needed to use this logic multiple times inside one
StringBuilder.AppendFormatcall: