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

SPGen - Stored Procedure Generator

, 12 Dec 2002 MIT
A simple app which generates INSERT and UPDATE SQL Stored Procedure code
spgen_exe.zip
SPGen.exe
Interop.SQLDMO.dll
spgen_src.zip
app.ico
table.jpg
database.jpg
using System;
using System.Collections;

namespace Bluegrass.Data
{
	/// <summary>
	/// Provides helper functions for SQLDMO
	/// </summary>
	public class SQLDMOHelper
	{
		public string ServerName;
		public string UserName;
		public string Password;
		public string Database;
		public string Table;

		/// <summary>
		/// SQLDMO.SQLServer Connection
		/// </summary>
		private SQLDMO.SQLServer Connection = new SQLDMO.SQLServerClass();

		/// <summary>
		/// Connects this.Connection
		/// </summary>
		public void Connect()
		{
			Connection.Connect(ServerName, UserName, Password);
		}

		/// <summary>
		/// DisConnects this.Connection
		/// </summary>
		public void DisConnect()
		{
			Connection.DisConnect();
		}

		/// <summary>
		/// An array of Registered SQL Servers
		/// </summary>
		/// <remarks>
		/// Thanks to Leppie @ CodeProject for the following
		/// </remarks>
		public Array RegisteredServers
		{
			get
			{
				ArrayList aServers = new ArrayList();
				SQLDMO.ApplicationClass acServers = new SQLDMO.ApplicationClass();

				for (int iServerGroupCount = 1; iServerGroupCount <= acServers.ServerGroups.Count; iServerGroupCount++)
					for (int iServerCount = 1; iServerCount <= acServers.ServerGroups.Item(iServerGroupCount).RegisteredServers.Count; iServerCount++)
						aServers.Add(acServers.ServerGroups.Item(iServerGroupCount).RegisteredServers.Item(iServerCount).Name);

				return aServers.ToArray();
			}
		}

			/// <summary>
			/// An array of Databases in a SQL Server
			/// </summary>
			public Array Databases
		{
			get
			{
				ArrayList aDatabases = new ArrayList();

				foreach(SQLDMO.Database dbCurrent in Connection.Databases)
					aDatabases.Add(dbCurrent.Name);

				return aDatabases.ToArray();
			}
		}

		/// <summary>
		/// Array of Tables in a Database
		/// </summary>
		public Array Tables
		{
			get
			{
				ArrayList aTables = new ArrayList();
				SQLDMO.Database dbCurrent = (SQLDMO.Database)Connection.Databases.Item(this.Database, Connection);

				foreach(SQLDMO.Table tblCurrent in dbCurrent.Tables)
					aTables.Add(tblCurrent.Name);
				
				return aTables.ToArray();
			}
		}

		/// <summary>
		/// A SQLDMO.Columns collection of Fields (Columns) in a Table
		/// </summary>
		public SQLDMO.Columns Fields
		{
			get
			{
				SQLDMO.Database dbCurrent = (SQLDMO.Database)Connection.Databases.Item(this.Database, Connection);
				SQLDMO.Table tblCurrent = (SQLDMO.Table)dbCurrent.Tables.Item(this.Table, Connection);

				return tblCurrent.Columns;
			}
		}
	}
}

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 MIT License

Share

About the Author

Paul Watson
Web Developer TSSG
Ireland Ireland
Paul is an internet developer living in Dublin, Ireland though home is still South Africa.
 
He believes in self-taught programming skills, standards based thinking and in the power of the common man.
 
Oh, and he loves photography. Make sure you don't get caught in the corner of a party when he has that photographic gleam in his eye. And if you were wondering about that bed-head photograph, wonder no longer...
Follow on   Twitter

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 13 Dec 2002
Article Copyright 2002 by Paul Watson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid