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
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
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
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
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
using System;
using System.Data;
using System.Data.SqlClient;

namespace DBHelper
{
#if(truenot)
   public class ParameterCollection: System.Collections.CollectionBase
   {
      SqlParameterCollection coll;

      public ParameterCollection(SqlParameterCollection coll)
      {
         this.coll = coll;
      }

      public new int Count 
      {
         get {return coll.Count;}
      }

      public virtual Parameter this[int index]
      {
         get
         {
            return new Parameter(coll[index]);
         }
         set
         {
            coll[index] = value.SqlParameter;
         }
      }
   }
#endif

   public class SPCollection: System.Collections.CollectionBase
   {
      public SPCollection()
      {
         // empty
      }

//      public SPCollection Create 
//      {
//         get 
//         {
//            SPCollection output = new SPCollection();
//            foreach (StoredProc sp in this)
//            {
//               if (sp.Create) output.Add(sp);
//            }
//            return output;
//         }
//      }
//
//      public SPCollection CreateStrong
//      {
//         get 
//         {
//            SPCollection output = new SPCollection();
//            foreach (StoredProc sp in this)
//            {
//               if (sp.CreateStrong) output.Add(sp);
//            }
//            return output;
//         }
//      }

      public SPCollection(StoredProc[] items)
      {
         this.AddRange(items);
      }

      public SPCollection(SPCollection items)
      {
         this.AddRange(items);
      }

      public virtual void AddRange(StoredProc[] items)
      {
         foreach (StoredProc item in items)
         {
            this.List.Add(item);
         }
      }

      public virtual void AddRange(SPCollection items)
      {
         foreach (StoredProc item in items)
         {
            this.List.Add(item);
         }
      }

      public void Add(string name)
      {
         //quickfix to "filter" source safe stuff
         if (!name.StartsWith("dt_"))
            Add(new StoredProc(name));
      }

      public virtual void Add(StoredProc value)
      {
         //if ((value.Name.ToLower().IndexOf("get") > -1) |
         //   (value.Name.ToLower().IndexOf("select") > -1) )
         //   value.CreateStrong = true;
         this.List.Add(value);
      }

      public bool Contains(string name)
      {
         foreach (StoredProc item in this)
         {
            if (item.Name == name) return true;
         }
         return false;
      }

      public virtual bool Contains(StoredProc value)
      {
         return this.List.Contains(value);
      }

      public virtual int IndexOf(StoredProc value)
      {
         return this.List.IndexOf(value);
      }

      public virtual void Insert(int index, StoredProc value)
      {
         this.List.Insert(index, value);
      }

      public virtual StoredProc this[int index]
      {
         get
         {
            return (StoredProc) this.List[index];
         }
         set
         {
            this.List[index] = value;
         }
      }

      public StoredProc this[string name]
      {
         get 
         {
            foreach(StoredProc sp in this)
            {
               if (sp.Name == name) return sp;
            }
            return null;
         }
      }

      public virtual void Remove(StoredProc value)
      {
         this.List.Remove(value);
      }

      public class Enumerator: System.Collections.IEnumerator
      {
         private System.Collections.IEnumerator wrapped;

         public Enumerator(SPCollection collection)
         {
            this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
         }

         public StoredProc Current
         {
            get
            {
               return (StoredProc) (this.wrapped.Current);
            }
         }

         object System.Collections.IEnumerator.Current
         {
            get
            {
               return (StoredProc) (this.wrapped.Current);
            }
         }

         public bool MoveNext()
         {
            return this.wrapped.MoveNext();
         }

         public void Reset()
         {
            this.wrapped.Reset();
         }
      }
        
      public new virtual SPCollection.Enumerator GetEnumerator()
      {
         return new SPCollection.Enumerator(this);
      }
   }

   /// <summary>
   /// A dictionary with keys of type SqlDbType and values of type Type
   /// </summary>
   public class SqlDbTypeToTypeAssociation: System.Collections.DictionaryBase
   {
      /// <summary>
      /// Initializes a new empty instance of the SqlDbTypeToTypeAssociation class
      /// </summary>
      public SqlDbTypeToTypeAssociation()
      {
         // empty
      }

      /// <summary>
      /// Gets or sets the Type associated with the given SqlDbType
      /// </summary>
      /// <param name="key">
      /// The SqlDbType whose value to get or set.
      /// </param>
      public virtual Type this[SqlDbType key]
      {
         get
         {
            return (Type) this.Dictionary[key];
         }
         set
         {
            this.Dictionary[key] = value;
         }
      }

      /// <summary>
      /// Adds an element with the specified key and value to this SqlDbTypeToTypeAssociation.
      /// </summary>
      /// <param name="key">
      /// The SqlDbType key of the element to add.
      /// </param>
      /// <param name="value">
      /// The Type value of the element to add.
      /// </param>
      public virtual void Add(SqlDbType key, Type value)
      {
         this.Dictionary.Add(key, value);
      }

      /// <summary>
      /// Determines whether this SqlDbTypeToTypeAssociation contains a specific key.
      /// </summary>
      /// <param name="key">
      /// The SqlDbType key to locate in this SqlDbTypeToTypeAssociation.
      /// </param>
      /// <returns>
      /// true if this SqlDbTypeToTypeAssociation contains an element with the specified key;
      /// otherwise, false.
      /// </returns>
      public virtual bool Contains(SqlDbType key)
      {
         return this.Dictionary.Contains(key);
      }

      /// <summary>
      /// Determines whether this SqlDbTypeToTypeAssociation contains a specific key.
      /// </summary>
      /// <param name="key">
      /// The SqlDbType key to locate in this SqlDbTypeToTypeAssociation.
      /// </param>
      /// <returns>
      /// true if this SqlDbTypeToTypeAssociation contains an element with the specified key;
      /// otherwise, false.
      /// </returns>
      public virtual bool ContainsKey(SqlDbType key)
      {
         return this.Dictionary.Contains(key);
      }

      /// <summary>
      /// Determines whether this SqlDbTypeToTypeAssociation contains a specific value.
      /// </summary>
      /// <param name="value">
      /// The Type value to locate in this SqlDbTypeToTypeAssociation.
      /// </param>
      /// <returns>
      /// true if this SqlDbTypeToTypeAssociation contains an element with the specified value;
      /// otherwise, false.
      /// </returns>
      public virtual bool ContainsValue(Type value)
      {
         foreach (Type item in this.Dictionary.Values)
         {
            if (item == value)
               return true;
         }
         return false;
      }

      /// <summary>
      /// Removes the element with the specified key from this SqlDbTypeToTypeAssociation.
      /// </summary>
      /// <param name="key">
      /// The SqlDbType key of the element to remove.
      /// </param>
      public virtual void Remove(SqlDbType key)
      {
         this.Dictionary.Remove(key);
      }

      /// <summary>
      /// Gets a collection containing the keys in this SqlDbTypeToTypeAssociation.
      /// </summary>
      public virtual System.Collections.ICollection Keys
      {
         get
         {
            return this.Dictionary.Keys;
         }
      }

      /// <summary>
      /// Gets a collection containing the values in this SqlDbTypeToTypeAssociation.
      /// </summary>
      public virtual System.Collections.ICollection Values
      {
         get
         {
            return this.Dictionary.Values;
         }
      }
   }

}

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

About the Author

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

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