Archive | ASP.NET/C#

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

Continue Reading

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

Continue Reading
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 […]

Continue Reading
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 […]

Continue Reading
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 […]

Continue Reading
ASP.net

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

Continue Reading
ASP.net

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

Continue Reading

Powered by WordPress. Designed by Woo Themes