Joseph Michael Pesch
VP Programming

C# Convert Enum Array Into Typed Array Used in LINQ to SQL IN Query

by 30. March 2009 17:22

The example below take an enum array input variable, converts to an integer array variable for use in a LINQ to SQL IN clause type query:

    public enum FlagTypeCode
      NotAssigned = 0,
      SendToServicerBlocked = 100,
      SelectedForQCReview = 200
    public static IQueryable<ModFlagDate> LoadModFlagDate(FlagTypeCode[] FlagTypeCodeList, ref string ErrorMessage)
      int[] FlagTypeList = Array.ConvertAll(FlagTypeCodeList, value => (int) value);
      ModCalcDataContext db = new ModCalcDataContext();
      var rows = (from row in db.ModFlagDates
                        where FlagTypeList.Contains(row.FlagTypeCode)
                        select row);
      return rows;

Tags: ,

C# | LINQ to SQL

CSS Site Layout

by 30. March 2009 14:05

  <style type="text/css">
      font-family: calibri, tahoma, verdana, courier, times;
      width: 80%;
      background-color: #FFFFFF;
      margin-top: 50px;
      margin-bottom: 50px;
      margin-left: auto;
      margin-right: auto;
      padding: 0px;
      border: solid 1px #000000;
      padding: 15px;
      margin: 0px;
      text-align: center;
      border-bottom: solid 1px #000000;
      width: 25%;
      padding: 10px;
      margin-top: 1px;
      float: left;
      margin-left: 25%; /* Make at least as big as #nav width */
      min-height: 400px;
      margin-top: 1px;
      padding: 10px;
      border-left: solid 1px #000000;
      padding: 15px;
      margin: 0px;
      border-top: solid 1px #000000;
  <div id="outer">
    <div id="header">
    <div id="nav">
        <li>Let me not to the marriage of true minds</li>
        <li>Admit impediments; love is not love</li>
        <li>Which alters when it alteration finds</li>
    <div id="main">
        Main Content -- Love's not time's fool...</p>
    <div id="footer">
        Footer text -- Admit impediments...</p>

Tags: ,


Zune Registry Hack for Vista - Allows Use as Mass Storage Device

by 30. March 2009 13:40
  • Make sure your Zune is not plugged in and your Zune software isn’t running
  • Open up Regedit by going to the start menu and selecting “run”. Type regedt32 and hit “OK”
  • Browse to HKEY_LOCAL_MACHINE\System\ControlSet002\Enum\USB\
  • Search for “PortableDeviceNameSpace”. This should be contained in the Vid_####&Pid_####\########_-_########_-_########_-_########\Device Parameters within the above …\USB\ The ##’s listed here will be numbers and letters specific to your Zune.
  • Change the following values:
    • EnableLegacySupport to 1
    • PortableDeviceNameSpaceExcludeFromShell to 0
    • ShowInShell to 1
  • Plug in your Zune, and make sure the Zune Software starts up.
  • Hopefully at this point you can open up “My Computer” and browse your device, though it does NOT show up as a drive letter.

Tags: ,


LinqSql DBML Connection String from Web.Config

by 26. March 2009 14:38

By default the DBML object sets the connection string information on the properties tab of the designer (available when you click on the white space in the the ORM designer).  IMPORTANT NOTE: Although you can select a web.config entry from the drop-down list in the designer, it will actually store the detailed connection string information in the DBML.cs file and not actually re-read the web.config at run time.  To use a true dynamic web.config default (vs. this hard coded default) make sure the designer connection is blank as shown in screen shot below.

Add partial class like this: 

namespace CRM {
publicpartialclassCRMDataContext : System.Data.Linq.DataContext

public CRMDataContext() : base(System.Configuration.ConfigurationManager.ConnectionStrings["CRM"].ConnectionString, mappingSource)

Tags: ,


Copying .Net Assembly DLL from One Computer to Another

by 25. March 2009 23:33

1) cmd window to "C:\Windows\Assembly\GAC_MSIL" then use the "dir" command (use TAB key to get auto-complete help on directories) to navigate down into folder that contains target .DLL

2) Copy the .DLL to a folder (like "C:\Temp")

3) Copy the .DLL to a folder on the target machine.

4) On the target machine run "Assembly" (from the windows run).

5) Drag the .DLL onto the Assembly window.

Tags: ,


C# System.Drawing.Color from HTML Color String

by 23. March 2009 20:20

System.Drawing.Color OrangeColor = System.Drawing.ColorTranslator.FromHtml("#CE56CC");

You can also translate colors without the ColorTranslator class (which may be useful if you are using the Compact Framework).

System.Drawing.Color only supports creating custom colors using it's FromArgb method, which requires base-10 inputs. Therefore, two conversion functions are needed - a conversion from decimal to hexadecimal, and a conversion from a 6 character string to three numeric parts (one each for red, green, and blue).

Source CodeThe first function handles the safe conversion of a hexadecimal (base-16) number to decimal (base-10).

1protected int HexStringToBase10Int(string hex)
3    int base10value = 0;
5    try   ...{ base10value = System.Convert.ToInt32(hex, 16); }
6    catch ...{ base10value = 0; }
8    return base10value;

The next function breaks the hexadecimal string into parts, removes a leading # (so you can pass it #FF00FF or FF00FF with the same result), and then converts the hexadecimal parts into decimal, and creates a color using the red, green, and blue value integers.

 1protected System.Drawing.Color HexStringToColor(string hex)
 3    hex = hex.Replace("#", "");
 5    if (hex.Length != 6)
 6        throw new Exception(hex +
 7            " is not a valid 6-place hexadecimal color code.");
 9    string r, g, b;
11    r = hex.Substring(0, 2);
12    g = hex.Substring(2, 2);
13    b = hex.Substring(4, 2);
15    return System.Drawing.Color.FromArgb(HexStringToBase10Int(r),
16                                         HexStringToBase10Int(g),
17                                         HexStringToBase10Int(b));


Tags: ,


SQL GoTo Statement

by 13. March 2009 18:06

declare @i int, @var int set @i = 1
while @i <= 10 begin
  printconvert(varchar(10), @i)+': while'

set @var = 1 goto Code1 ContinueWhile:

set @i = @i + 1
goto EndProcess Code1:

printconvert(varchar(10), @i)+': Code: '+convert(varchar(10), @var)
if @var < 5 begin
set @var = @var + 1 goto Code1 end

goto ContinueWhile EndProcess:


Tags: ,

SQL Server

Excel Formula to Convert Date Cell to Text Cell

by 13. March 2009 15:22

This formula will take the Date value from cell A1 and convert it to either the word null if no date is in the cell or a string representation of the date in small quotes (usefull for generating SQL insert/update strings):

=IF(A1="","null","'"&TEXT(MONTH(A1),"00") & "-" & TEXT(DAY(A1),"00") & "-" & TEXT(YEAR(A1), "0000")&"'")

Tags: ,


Oracle to_date() Function

by 12. March 2009 18:58

Date formatting in Oracle

select to_date('02/17/2009 12:22:01 PM', 'mm/dd/yyyy HH:MI:SS AM') from dual


Tags: ,


Visual Studio XML Documentation Reference

by 8. March 2009 21:34

To add XML documentation:

1) Enable via Project Properties (on the Build tab).

2) Build project and you will receive warnings about all Public members that are not documented (you can double-click to add appropriate documentation in each section).

3) Install Sandcastle ( and  Visual Studio 2008 SDK (

4) Run Sandcastle program (in my case I ran it from C:\Program Files\Sandcastle\Examples\generic\SandcastleGui.exe)

5) Once you click on build the tool will generate HxS file under the sandcastle installation directory (named whatever you selected in the "Name" field). We will use this file to create a setup.exe which when installed integrates it with Visual Studio.

6) Open Visual Studio 2008 and click File -> New Project : In the new project dialog expand "Other Project Types" and select Extensibility. On the right hand side select "Help Integration Wizard" and enter a name for the project and click OK.  In the wizard that appears select "Setup project" and click Next.  In the next step select the HxS file we created in Step 5 above.  Visual Studio now creates 2 projects a Merge Module project and a setup project. Click on the setup project and modify its properties as needed.

7) Now compile the setup project to generate an MSI and a setup.exe file which when installed integrates the help with VS.NET.  You might have to close and re-open all instances VS.NET to see the change.  Now type in a class name in the code editor and press F1.  VS.NET should directly take you to the documentation associated with that class.

Below are the basic XML documetation tags you can apply to the source code for building the help file.

Documentation Sections

  • <summary>

    A short description of the item; describe the members of the type here.

  • <remarks>

    The "Remarks" section of the documentation; specify overview information here.

  • <example>

    The "Example" section of the documentation.

  • <seealso>

    A link in the "See Also" section of the documentation.

    <seealso cref="member">text</seealso>

Member Documentation

  • <param>

    Describes a parameter to a method.

    <param name="name">text</param>
  • <returns>

    The return value of a method.

  • <exception>

    The exceptions that can be thrown.

    <exception [cref="type"]>text</exception>
  • <value>

    Describes the value of a property.

  • <permission>

    The permission applied to a member.

    <permission [cref="type"]>text</permission>

Text Formatting

  • <c>

    Format characters as code within other text.

  • <code>

    Multiline section of code.

  • <see cref>

    A link to a type, member or field in the current compilation environment.

    <see cref="member">text</see>
  • <see langword>

    Undocumented. A link to a keyword in the language of the current compilation environment, e.g. null.

    <see langword="keyword"/>
  • <paramref>

    A reference to a parameter within other text.

    <paramref name="name"/>
  • <list>

    A list of items.

    <list type="[bullet|number|table]">
  • <para>

    A paragraph within other text.

  • <include>

    Refer to comments in another file.

    <include file='filename' path='tagpath[@name="id"]' />

Tags: ,

Visual Studio

JQuery Reference

by 8. March 2009 21:08

MSDN Magazine article: Explore Rich Client Scripting With jQuery, Part 1

Tags: ,