Archive for January 29th, 2007
Retrieving Value from a DataSet

In the continued spirit of posting whenever I answer a question of mine, here’s a simple snippet of C# code that retrieves a value directly from a dataset.

myVar = myDataSet.Tables[0].Rows[0]["myColumnName"];

Note that the string name can replace the numeric indexes used to more accurately identify a table.

Formatting Strings in C#

This article provides a great overview for formatting strings in C#. As I have been dabbling with a new GUI for my database, I’ve been having fits with formatting certain types of strings. This site helped me find my way…

 String Formatting in C#

Of particular help were these examples:

String.Format(”{0:$#,##0.00;($#,##0.00);Zero}”, value);

This will output “$1,240.00″ if passed 1243.50. It will output the same format but in parentheses if the number is negative, and will output the string “Zero” if the number is zero.

String.Format(”{0:(###) ###-####}”, 8005551212);

This will output “(800) 555-1212″.

If you have any questions about string formatting, or pretty much anything related, drop by the Forum and ask it there. It’s an easier place to talk than in the comments section here.

Happy Coding!