Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your comment was the magic key. I did not know that the old interface was deprecated. Finding the right code was a bit of a challenge, as there is sadly no "COLUMN_NAME" on the Indexes collection or "PRIMRY" on the Columns collections, so I have to go through twice, but still, the new version is far better.</p> <pre><code>public String GetPrimaryKey(String strTable) </code></pre> <p>{ try { Boolean bIsPrimary = false; String strIndexName = null; String strColumnName = null; String[] strRestricted = new String[4] { null, null, strTable, null }; DataTable oSchemaIndexes = null; DataTable oSchemaIndexColumns = null;</p> <pre><code> // Make sure that there is a connection. if (ConnectionState.Open != this.m_oConnection.State) this.m_oConnection.Open(); // DATABASE: Get the schemas needed. oSchemaIndexes = this.m_oConnection.GetSchema("Indexes", strRestricted); oSchemaIndexColumns = this.m_oConnection.GetSchema("IndexColumns", strRestricted); // Get the index name for the primary key. foreach (DataRow oRow in oSchemaIndexes.Rows) { // If we have a primary key, then we found what we want. strIndexName = oRow["INDEX_NAME"].ToString(); bIsPrimary = (Boolean)oRow["PRIMARY"]; if (true == bIsPrimary) break; } // If no primary index, bail. if (false == bIsPrimary) return null; // Get the corresponding column name. foreach (DataRow oRow in oSchemaIndexColumns.Rows) { // Get the column name. if (strIndexName == (String)oRow["INDEX_NAME"]) { strColumnName = (String)oRow["COLUMN_NAME"]; break; } } return strColumnName; } catch (Exception ex) { MessageBox.Show(ex.Message); } return null; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload