Tag Archives | c#

Excel Interop: Move a Worksheet

Excel Interop: Move a Worksheet

Howdy! I spent an hour or so trying to figure this one out. Hope this helps someone. I am using Excel Interop with C#, and have a method that calls the .Move(Before, After) function on a Worksheet. I was trying to move a sheet to the end, and was using this code: mySheet.Move(null, myWorkbook.Worksheets[myWorkbook.Worksheets.Count]) I […]

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

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

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

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

Powered by WordPress. Designed by Woo Themes