Creating a SQL Server Stored Procedure Generator using WPF
page 6 of 8
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 15773/ 269

Stored Procedure Creation

To create stored procedures requires straight text processing. To make the process simpler, I used a StringBuilder. Stored procedure parameters are created by looping through the columns of a table, using the column name directly. So if a column is dbo.tblEvents.EventID, it will be used directly and the parameter name will be @EventID. Column names work the same way; they use only the name of the column, so the "@" sign does not need appended to the beginning.

Below is the generation of a selection procedure. GetShortTableName gets the name of the table without the schema prefix, and RenderColumnList renders a vertical list of columns, with or without the "@" and with or without the data type.

Listing 10

private void GenerateSelectProc(TreeViewItem item)
{
      string tableName = item.Header.ToString();
      StringBuilder builder = new StringBuilder();
 
      builder.AppendLine(string.Format("create procedure dbo.Select{0}", 
       this.GetShortTableName(tableName)));
      builder.AppendLine();
      builder.AppendLine("as");
      builder.AppendLine();
 
      builder.Append("select");
      this.RenderColumnList(builder, item, falsefalse);
      builder.AppendLine(string.Format("from\t{0}", tableName));
 
      this.SelectProcedure.Text = builder.ToString();
}

View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 5 and 3 and type the answer here:

User Comments

Title: Great example   
Name: gabo
Date: 9/1/2008 3:59:25 PM
Comment:
As a matter of fact I use it all the time. Thanks.
Title: A good start   
Name: Ralph D. Wilson II
Date: 9/19/2007 10:36:05 AM
Comment:
This presents a good start toward creating Stored Procs; however, I can see several limitations in it. Perhaps the most glaring limitation is the fact that it appears to only facilitate the creation of very basic SP's and, while that is useful, I am assisting C#/ASP.Net developers in the creation of much more complex SP's.
Title: type   
Name: Nitin
Date: 9/19/2007 6:17:17 AM
Comment:
it is good but not enough
Title: Useful   
Name: Niall
Date: 8/30/2007 3:32:49 AM
Comment:
This is interesting and I can see a very good use for this type of programming in my current project. One reservation I have though is the use of the WPF. Specifically the Presentation part of WPF.
Title: Code is Attached   
Name: Brian Mains
Date: 8/26/2007 7:26:33 PM
Comment:
The code is attached; see the downloads section.
Title: download this software   
Name: ankti
Date: 8/26/2007 4:22:23 PM
Comment:
i want to see this software






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 10/7/2008 7:15:09 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search