Posts Tagged ‘c#’

C#: Break vs. Continue in Foreach Loops

Tuesday, March 16th, 2010

A C# Quick Tip: You’ve probably seen ‘break’ before in Switch Case statements, but it also plays an important role in Foreach Loops.

To break completely out of a foreach loop (foregoing all the remaining loops), use: break;

To go to the next iteration in the loop, use: continue;

(more…)

Popularity: 3%

C#: That Pesky DBNull Error in Datatables

Monday, March 15th, 2010

Datatables and Tableadapters are one of the most beautiful things about C# and Visual Studio, until you’re processing rows in your datatable and you get something that reads like “The value for column ‘your_column’ in table ‘your_table’ is DBNull.”  If you go a little further, you may get:  “Exception Details: System.InvalidCastException: Specified cast is not valid.”  You may go to your Datatable in your Dataset and start trying to change the NullValue for the offending column or trying to change the DefaultValue in the column properties, but chances are that the data type will not let you change that NullValue.  It will insist on “(Throw Exception)”. (more…)

Popularity: 3%

C# – SQL Server Foreign Key, Unique constraints

Wednesday, May 27th, 2009

unique_key_constraintI got tripped up today with a particularly nasty Join statement that worked perfectly form 90% of the queries, but was blowing up at times.  The error message was: 

(more…)

Popularity: 12%