Archive | ASP.NET/C# RSS feed for this section
c-sharp-nullreferenceerror

C# – NullReferenceException with TableAdapter and Scalar Values

Ok, I’ve been hacking around this particular problem for a month now, but think I’ve got a bead on how to stop it. So, I hope this helps someone! The Situation I’ve got a TableAdapter in C# and I’m using a Query to return a scalar value that ultimately becomes a double data type. The [...]

Read full story Comments { 0 }

C# / VSTO – Using Excel Ranges

Using Visual Studio Tools for Office (VSTO) with Excel lets you use C# (or your other favorite .NET language to leverage the power of Excel. But you will have to learn how the syntax for the Excel object model as opposed to just using VBA syntax. This post shows you how to use Excel ranges [...]

Read full story Comments { 0 }

C# – VSTO – Get Last Used Row or Cell in Excel Spreadsheet

I have had the opportunity to get my fingers dirty with Visual Studio Tools for Office, at long last.  My project brought me back to an old familiar problem in Excel, finding the last used row in a spreadsheet. This applies equally to C#, VB, and VBA.  You just have to get access to the [...]

Read full story Comments { 2 }

C#: Break vs. Continue in Foreach Loops

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; When is ‘break’ useful? It is [...]

Read full story Comments { 1 }
datatable

C#: That Pesky DBNull Error in Datatables

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

Read full story Comments { 1 }
hideme

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

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. Web.config Settings for Role-based Menu Security 1) When you declare your sitemap provider, turn sucrityTrimmingEnabled to [...]

Read full story Comments { 1 }
relax_constraints

C# – SQL Server Foreign Key, Unique constraints

I 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:  Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. I looked and looked at this SQL code: It looked [...]

Read full story Comments { 2 }
C# – Convert String Array to a List (.Net 2.0)

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

So 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. If you’re stuck in .Net [...]

Read full story Comments Off
ASP.NET – Get User Name Under Windows Authentication

ASP.NET – Get User Name Under Windows Authentication

Getting 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: Be sure to add the Security reference: Thats it! [UPDATE] Check out the comments below for some additional suggestions [...]

Read full story Comments { 7 }

Excel Spreadsheet of US States

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. But no more. See full post for download.

Read full story Comments { 14 }