Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » Utilities » Downloads
 
Add your own
alternative version

SQL Stored Procedure Wrapper & Typed DataSet Generator for .NET

, 7 Dec 2002 BSD
This a small tool that will generate static methods in a class that acts as wrapper for SQL stored procedures. It either outputs a source file or a compiled assembly. Also supports automatic DataSet generation.
dbhelper-1.0.zip
DBHelper
CVS
Base
Baserev
Entries
Repository
Root
DBHelper.suo
DBHelper.vssscc
SP
CVS
Base
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
SPTestApp
App.ico
CVS
Base
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.1.zip
Baserev
Entries
Repository
Root
DBHelper.suo
DBHelper.vssscc
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.2.zip
Baserev
Entries
Repository
Root
DBHelper.suo
DBHelper.vssscc
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.3.zip
Baserev
Entries
Repository
Root
DBHelper.suo
DBHelper.vssscc
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.4.zip
Baserev
Entries
Repository
Root
dbh.gif
DBHelper.suo
DBHelper.vssscc
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.5.demo.zip
SPTestApp.exe
DBHelper.dll
Interop.MSDASC.dll
dbhelper-1.5.src.zip
Baserev
Entries
Repository
Root
dbh.gif
DBHelper.suo
DBHelper.vssscc
Baserev
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-1.6.demo.zip
SPTestApp.exe
DBHelper.dll
Interop.MSDASC.dll
dbhelper-1.6.src.zip
Baserev
Entries
Repository
Root
dbh.gif
DBHelper.suo
DBHelper.vssscc
Baserev
Diff
Entries
Repository
Root
DBHelper.csproj.user
DBHelper.csproj.vspscc
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
SPTestApp.csproj.vspscc
dbhelper-16demo.zip
SPTestApp.exe
DBHelper.dll
Interop.MSDASC.dll
dbhelper-16src.zip
Baserev
Entries
Repository
Root
dbh.gif
Baserev
Entries
Repository
Root
DBHelper.csproj.user
App.ico
Baserev
Entries
Repository
Root
SPTestApp.csproj.user
// SBCollectionGenerator.cs: Chris Sells [csells@sellsbrothers.com]
#region Copyright � 2002 Chris Sells
/* This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, subject to the following restrictions:
 * 
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software in a
 *    product, an acknowledgment in the product documentation is requested, as
 *    shown here:
 * 
 *    Portions copyright � 2002 Chris Sells (http://www.sellsbrothers.com/).
 * 
 * 2. No substantial portion of this source code may be redistributed without
 *    the express written permission of the copyright holders, where
 *    "substantial" is defined as enough code to be recognizably from this code.
 */
#endregion
#region Usage
/*
 * Registration:
 * c:/> regasm /codebase CollectionGen.dll
 *
 * Unregistration:
 * c:/> regasm /unregister CollectionGen.dll
 * 
 * Usage:
 * Add a .xml file in the correct format and set:
 *  Build Action: Content
 *  Custom Tool: SBCollectionGenerator
 * 
 * Format of .xml file:

<typeSafeCollections>
    <typeSafeCollection>
        <templateKind>Vector</templateKind>
        <itemType>int</itemType>
        <collectionName>IntegerCollection</collectionName>
        <collectionNamespace>MyCollections</collectionNamespace>
    </typeSafeCollection>
    <typeSafeCollection>
        <templateKind>Vector</templateKind>
        <itemType>System.Drawing.Point</itemType>
        <collectionName>PointCollection</collectionName>
        <collectionNamespace>MyCollections</collectionNamespace>
    </typeSafeCollection>
    <typeSafeCollection>
        <templateKind>HashTable</templateKind>
        <keyType>string</keyType>
        <itemType>int</itemType>
        <collectionName>StringIntHash</collectionName>
        <collectionNamespace>MyCollections</collectionNamespace>
    </typeSafeCollection>
    <typeSafeCollection>
        <templateKind>HashTable</templateKind>
        <keyType>string</keyType>
        <itemType>System.Drawing.Point</itemType>
        <collectionName>StringPointHash</collectionName>
        <collectionNamespace>MyCollections</collectionNamespace>
    </typeSafeCollection>
</typeSafeCollections>
*/
#endregion
#region History
// 8/27/02:
//  -Chris Sells [csells@sellsbrothers.com] split out VS.NET-specific functionality.
// 7/1/02:
//  -Chris Sells [csells@sellsbrothers.com] added self-registration support.
#endregion

using System;
using Microsoft.VSDesigner.CodeGenerator; // vs.net\Common7\IDE\Microsoft.VSDesigner.dll
//using System.Windows.Forms;
using Microsoft.Win32;  // Registry
using System.Runtime.InteropServices;   // ComRegisterFunction et al

namespace DBHelper
{
   public abstract class VsCollectionGenerator : BaseCodeGeneratorWithSite
   {
      public byte[] GenerateCode(CollectionGenerator generator, string fileName, string fileContents)
      {
         string code = "";
         try
         {
            code = generator.GenerateCodeFromXml(fileContents);
         }
         catch( Exception e )
         {
            code = "***ERROR***\n" + e.Message;
         }
         return System.Text.Encoding.ASCII.GetBytes(code);
      }

      protected static Guid CSharpCategoryGuid = new Guid("{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}");
      protected static Guid VBCategoryGuid = new Guid("{164B10B9-B200-11D0-8C61-00A0C91E29D5}");

      protected static string GetKeyName(Guid categoryGuid)
      {
         string name = "SBCollectionGenerator";
         return @"SOFTWARE\Microsoft\VisualStudio\7.0\Generators\{" + categoryGuid.ToString() + @"}\" + name;
      }

      protected static void RegisterCustomTool(Guid categoryGuid, Type generatorType, string desc)
      {
         /*
             * [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.0\Generators\{FAE04EC1-301F-11D3-BF4B-00C04F79EFBC}\SBCollectionGenerator]
             * @="Sells Brothers C# Code Generator for Type-Safe Collections"
             * "CLSID"="{3D05404F-6ECF-42b2-8435-2AB63382FFA2}"
             * "GeneratesDesignTimeSource"=dword:00000001
             */

         // Assume GUID is associated with this class via the GuidAttribute
         // Since this is required for COM interop to work with VS.NET, this seems reasonable
         string  generatorGuid = ((GuidAttribute)(generatorType.GetCustomAttributes(typeof(GuidAttribute), true)[0])).Value;

         using( RegistryKey key = Registry.LocalMachine.CreateSubKey(GetKeyName(categoryGuid)) )
         {
            key.SetValue("", desc);
            key.SetValue("CLSID", "{" + generatorGuid + "}");
            // TODO : Does not create a DWORD entry as desired. Seems to work anyway though <g>.
            key.SetValue("GeneratesDesignTimeSource", (uint)1);
         }
      }

      protected static void UnregisterCustomTool(Guid categoryGuid, Type generatorType)
      {
         Registry.LocalMachine.DeleteSubKey(GetKeyName(categoryGuid), false);
      }
   }

   [Guid("F6144A30-C061-44e4-A50E-1BB10A8B8A45")]
   public class VsCSharpCollectionGenerator : VsCollectionGenerator
   {
      public override byte[] GenerateCode(string fileName, string fileContents)
      {
         return GenerateCode(new CSharpCollectionGenerator(), fileName, fileContents);
      }

      [ComRegisterFunction]
      public static void RegisterClass(Type t)
      {
         RegisterCustomTool(CSharpCategoryGuid, typeof(VsCSharpCollectionGenerator), "Sells Brothers C# Code Generator for Type-Safe Collections");
      }

      [ComUnregisterFunction]
      public static void UnregisterClass(Type t)
      {
         UnregisterCustomTool(CSharpCategoryGuid, typeof(VsCSharpCollectionGenerator));
      }
   }

   [Guid("9581541A-C790-41f3-A524-58469FCBB212")]
   public class VsVBCollectionGenerator : VsCollectionGenerator
   {
      public override byte[] GenerateCode(string fileName, string fileContents)
      {
         return GenerateCode(new VBCollectionGenerator(), fileName, fileContents);
      }

      [ComRegisterFunction]
      public static void RegisterClass(Type t)
      {
         RegisterCustomTool(VBCategoryGuid, typeof(VsVBCollectionGenerator), "Sells Brothers VB Code Generator for Type-Safe Collections");
      }

      [ComUnregisterFunction]
      public static void UnregisterClass(Type t)
      {
         UnregisterCustomTool(VBCategoryGuid, typeof(VsVBCollectionGenerator));
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License

Share

About the Author

leppie
Software Developer
South Africa South Africa
No Biography provided
Follow on   Twitter

| Advertise | Privacy | Mobile
Web02 | 2.8.141029.1 | Last Updated 8 Dec 2002
Article Copyright 2002 by leppie
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid