private void ShowTableColumns(Bamboo.Mssql.TableColumnCollection columns) { foreach (Bamboo.Mssql.TableColumn column in columns) { this.listView.Items.Add(new System.Windows.Forms.ListViewItem(column.Name, Images.Column)); } }
public ColumnsTreeNode(Bamboo.Mssql.TableColumnCollection columns) { this.Text = "Columns"; this.Tag = columns; this.ImageIndex = Images.Columns; this.SelectedImageIndex = Images.Columns; foreach (Bamboo.Mssql.TableColumn column in columns) { this.Nodes.Add(new ColumnTreeNode(column)); } }
public static Bamboo.Mssql.TableColumnCollection ReadTableColumns(string tableName, System.Data.SqlClient.SqlConnection connection) { Bamboo.Mssql.TableColumnCollection columns = new Bamboo.Mssql.TableColumnCollection(); string query = "SELECT COLUMN_NAME, IS_NULLABLE, (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ON INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.CONSTRAINT_NAME WHERE INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'PRIMARY KEY' AND INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME = INFORMATION_SCHEMA.COLUMNS.TABLE_NAME AND INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.COLUMN_NAME = INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME) AS IS_PRIMARY_KEY, (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ON INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME = INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.CONSTRAINT_NAME WHERE INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'FOREIGN KEY' AND INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME = INFORMATION_SCHEMA.COLUMNS.TABLE_NAME AND INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE.COLUMN_NAME = INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME) AS IS_FOREIGN_KEY, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' ORDER BY TABLE_NAME, ORDINAL_POSITION"; System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(query, connection); System.Data.SqlClient.SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Bamboo.Mssql.TableColumn column = new Bamboo.Mssql.TableColumn(); if (!dataReader.IsDBNull(dataReader.GetOrdinal("COLUMN_NAME"))) { column.Name = dataReader.GetString(dataReader.GetOrdinal("COLUMN_NAME")); } if (!dataReader.IsDBNull(dataReader.GetOrdinal("IS_NULLABLE"))) { string is_nullable = dataReader.GetString(dataReader.GetOrdinal("IS_NULLABLE")).Trim().ToUpper(); if (is_nullable == "YES") { column.IsNullable = true; } else if (is_nullable == "NO") { column.IsNullable = false; } } if (!dataReader.IsDBNull(dataReader.GetOrdinal("IS_PRIMARY_KEY"))) { int count = dataReader.GetInt32(dataReader.GetOrdinal("IS_PRIMARY_KEY")); if (count > 0) { column.IsPrimaryKey = true; } } if (!dataReader.IsDBNull(dataReader.GetOrdinal("IS_FOREIGN_KEY"))) { int count = dataReader.GetInt32(dataReader.GetOrdinal("IS_FOREIGN_KEY")); if (count > 0) { column.IsForeignKey = true; } } if (!dataReader.IsDBNull(dataReader.GetOrdinal("DATA_TYPE"))) { column.Datatype = dataReader.GetString(dataReader.GetOrdinal("DATA_TYPE")); } if (!dataReader.IsDBNull(dataReader.GetOrdinal("CHARACTER_MAXIMUM_LENGTH"))) { column.Length = dataReader.GetInt32(dataReader.GetOrdinal("CHARACTER_MAXIMUM_LENGTH")); } columns.Add(column); } dataReader.Close(); return(columns); }
private void sqlDatabaseTreeView_SelectionChanged(object sender, System.EventArgs e) { System.Windows.Forms.TreeNode selectedNode = this.sqlDatabaseTreeView.SelectedNode; if (selectedNode != null) { if (selectedNode is TablesTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); TablesTreeNode tablesTreeNode = (TablesTreeNode)selectedNode; Bamboo.Mssql.TableCollection tables = (Bamboo.Mssql.TableCollection)tablesTreeNode.Tag; this.ShowTables(tables); } else if (selectedNode is TableTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); TableTreeNode tableTreeNode = (TableTreeNode)selectedNode; Bamboo.Mssql.Table table = (Bamboo.Mssql.Table)tableTreeNode.Tag; this.ShowTableColumns(table.Columns); } else if (selectedNode is ColumnsTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); ColumnsTreeNode columnsTreeNode = (ColumnsTreeNode)selectedNode; Bamboo.Mssql.TableColumnCollection columns = (Bamboo.Mssql.TableColumnCollection)columnsTreeNode.Tag; this.ShowTableColumns(columns); } else if (selectedNode is ColumnTreeNode) { this.listView.Clear(); this.listView.View = System.Windows.Forms.View.Details; ColumnTreeNode columnTreeNode = (ColumnTreeNode)selectedNode; Bamboo.Mssql.TableColumn column = (Bamboo.Mssql.TableColumn)columnTreeNode.Tag; this.ShowTableColumn(column); } else if (selectedNode is ViewsTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); ViewsTreeNode viewsTreeNode = (ViewsTreeNode)selectedNode; Bamboo.Mssql.ViewCollection views = (Bamboo.Mssql.ViewCollection)viewsTreeNode.Tag; this.ShowViews(views); } else if (selectedNode is ViewTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); ViewTreeNode viewTreeNode = (ViewTreeNode)selectedNode; Bamboo.Mssql.View view = (Bamboo.Mssql.View)viewTreeNode.Tag; this.ShowViewColumns(view.Columns); } else if (selectedNode is ViewColumnsTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); ViewColumnsTreeNode viewColumnsTreeNode = (ViewColumnsTreeNode)selectedNode; Bamboo.Mssql.ViewColumnCollection columns = (Bamboo.Mssql.ViewColumnCollection)viewColumnsTreeNode.Tag; this.ShowViewColumns(columns); } else if (selectedNode is ViewColumnTreeNode) { this.listView.Clear(); this.listView.View = System.Windows.Forms.View.Details; ViewColumnTreeNode viewColumnTreeNode = (ViewColumnTreeNode)selectedNode; Bamboo.Mssql.ViewColumn column = (Bamboo.Mssql.ViewColumn)viewColumnTreeNode.Tag; this.ShowViewColumn(column); } else if (selectedNode is ProceduresTreeNode) { this.listView.View = System.Windows.Forms.View.List; this.listView.Columns.Clear(); this.listView.Clear(); ProceduresTreeNode proceduresTreeNode = (ProceduresTreeNode)selectedNode; Bamboo.Mssql.ProcedureCollection procedures = (Bamboo.Mssql.ProcedureCollection)proceduresTreeNode.Tag; this.ShowProcudures(procedures); } else if (selectedNode is ProcedureTreeNode) { this.listView.Clear(); this.listView.View = System.Windows.Forms.View.Details; ProcedureTreeNode procedureTreeNode = (ProcedureTreeNode)selectedNode; Bamboo.Mssql.Procedure procedure = (Bamboo.Mssql.Procedure)procedureTreeNode.Tag; this.ShowProcudure(procedure); } else { this.listView.Clear(); } } }