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

Tree Creation

To create the tree view, the table's information schema view is queried and the results are parsed. The table name is created in the format of schema.tablename. This node is created as a single string and to create a shorter version of the table name later requires splitting the name at the decimal point.

Columns are created in the format of name, followed by a comma, and then the data type/length combination (such as "EventID,varchar(10)"). To get the column name requires splitting by the comma between the name/data type. That is useful for later.

Listing 9

foreach (DataRow tableRow in _information.Tables["Tables"].Rows)
{
      string tableSchema = tableRow["TABLE_SCHEMA"].ToString();
      string tableName = tableRow["TABLE_NAME"].ToString();
      TreeViewItem tableItem = new TreeViewItem();
      tableItem.Header = string.Format("{0}.{1}", tableSchema, tableName);
      this.TablesListing.Items.Add(tableItem);
 
      DataView columnsView = _information.Tables["Columns"].DefaultView;
      columnsView.RowFilter = string.Format(
          "TABLE_NAME = '{1}' and TABLE_SCHEMA = '{0}'", tableSchema, tableName);
 
      for (int i = 0; i < columnsView.Count; i++)
      {
            DataRow columnRow = columnsView[i].Row;
            string columnName = columnRow["COLUMN_NAME"].ToString();
            string dataType = columnRow["DATA_TYPE"].ToString();
            int precision = (int)(columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") 
              ? 0 
              : columnRow["CHARACTER_MAXIMUM_LENGTH"]);
            precision = !columnRow.IsNull("NUMERIC_PRECISION") 
               ? (int)columnRow["NUMERIC_PRECISION"]
              : precision;
 
            string text = columnName + ", " + dataType;
            if (precision > 0)
                  text += "(" + precision.ToString() + ")";
 
            TreeViewItem columnItem = new TreeViewItem();
            columnItem.Header = text;
            tableItem.Items.Add(columnItem);
      }
}

All of the information gets pulled from the information schema views and creates the appropriate tree view items. To get the information back, it is collected from these tree view items and parsed appropriately.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 7 and 1 and type the answer here:

User Comments

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






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


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