private void cmbTables_SelectedIndexChanged(object sender, EventArgs e) { if (_initializing || SelectedKey == null) { return; } TableWrapper selTable = cmbTables.SelectedItem as TableWrapper; if (selTable == null) { SelectedKey.Table = selTable; return; } TableWrapper tbl = new TableWrapper(); tbl.ConnectionParams = _cp; tbl.ID = selTable.ID; tbl.LoadProperties(); tbl.LoadColumns(); SelectedKey.Table = tbl; lbPkCols.Items.Clear(); SelectedKey.Columns.Clear(); InitializeTableColumns(); }
private void PopulateTableData( ) { _table.LoadProperties(); _table.LoadColumns(); RenderTableProperties(); }
public void GetKey( ) { //Set the key Option string cmdText = "declare @cmplevel int select @cmplevel = cmptlevel from master..sysdatabases where name = DB_NAME() "; cmdText += "SELECT "; cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsDisabled') as IsDisabled,"; cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsNotRepl') as IsNotRepl,"; cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsUpdateCascade') as IsUpdateCascade,"; cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsDeleteCascade') as IsDeleteCascade,"; cmdText += " dbo.sysreferences.constid, CASE WHEN @cmplevel < 90 THEN USER_NAME(hostTable.uid) ELSE SCHEMA_NAME(hostTable.uid) END AS unamehost, hostTable.name AS host, hostTable.id as hostID, refTable.id as refID, CASE WHEN @cmplevel < 90 THEN USER_NAME(refTable.uid) ELSE SCHEMA_NAME(refTable.uid) END AS unameref, refTable.name AS ref"; cmdText += " FROM dbo.sysreferences INNER JOIN dbo.sysobjects hostTable ON dbo.sysreferences.fkeyid = hostTable.id INNER JOIN dbo.sysobjects refTable ON dbo.sysreferences.rkeyid = refTable.id"; cmdText += " WHERE (dbo.sysreferences.constid = " + ID.ToString() + ")"; using (SqlConnection conn = _cp.CreateSqlConnection(true, false)) { SqlDataReader reader = DbCmd.ExecuteReader(cmdText, conn); try { while (reader.Read()) { _notForReplication = Convert.ToBoolean(reader["IsNotRepl"]); _disabled = Convert.ToBoolean(reader["IsDisabled"]); _cascadeUpdate = Convert.ToBoolean(reader["IsUpdateCascade"]); _cascadeDelete = Convert.ToBoolean(reader["IsDeleteCascade"]); _hostTable.ID = Convert.ToInt64(reader["hostID"]); _hostTable.LoadProperties(); _hostTable.LoadColumns(); _refTable.ID = Convert.ToInt64(reader["refID"]); _refTable.LoadProperties(); _refTable.LoadColumns(); } } finally { reader.Close(); reader.Dispose(); } //Key referenced cmdText = "SELECT sysindexes.indid, sysindexes.name as keyName" + " FROM sysindexes, sysreferences " + " WHERE sysreferences.rkeyid=sysindexes.id AND sysreferences.rkeyindid=sysindexes.indid " + " AND sysreferences.rkeyid=" + _refTable.ID + " AND OBJECT_NAME(sysreferences.constid)='" + this.NormalizedName + "'"; SqlDataReader readerKey = DbCmd.ExecuteReader(cmdText, conn); try { while (readerKey.Read()) { _referencedKey.Id = (short)readerKey["indid"]; _referencedKey.Name = (string)readerKey["keyName"]; } } finally { readerKey.Close(); readerKey.Dispose(); } } }