Tag Archives: c#
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 }
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 }