Archive for the ‘ASP.NET/C#’ Category

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: 1%

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: 1%

ASP.NET: Hide Menu Items by Role with Security Trimming

Thursday, February 4th, 2010

ASP.NET makes authorizations and security fairly simple with its roleManager, Authentication, and SiteMap providers.  This quick hint only covers how to hide a particular menu item from the standard Menu and TreeList navigation components when using a SiteMap provider. (more…)

Popularity: 2%

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: 11%

C# – Convert String Array to a List (.Net 2.0)

Tuesday, May 19th, 2009

ASP.netSo you’ve got a C# string and you want to convert it to a List<string>.  Lists are one of the most efficient ways of storing…well…lists of things in .Net.  If you’re in .Net 3.0, it’s quite easy to go from a string array to a list by using the .ToList() function.

(more…)

Popularity: 16%

ASP.NET – Get User Name Under Windows Authentication

Tuesday, March 3rd, 2009

ASP.netGetting the authenticated user’s name when using Windows Authentication with ASP.NET is very simple.  I just keep having to go back to Google or dig out an old project to remember it, so here it is:

(more…)

Popularity: 38%

Excel Spreadsheet of US States

Thursday, February 12th, 2009

Here’s a simple Excel spreadsheet of US States and their abbreviations.  I don’t know how many times I’ve recreated this blooming thing.  I just found myself, once again trying to find a decent table of states to put into my Supple Forms states drop down list, and after ten minutes and finally getting it into an nice Excel table, I figured it was time to memorialize it forever here.  So, no more hunting around.  Here you go:

(more…)

Popularity: 40%

Get ASP.NET DropDownList Selected Value with jQuery

Friday, October 31st, 2008

With Microsoft’s recent announcement that they will begin shipping jQuery with Visual Studio, the little Javascript framework is about to hit the big time (it was already sort of big time, but this is BIG TIME).  And rightfully so.

(more…)

Popularity: 72%