2009-05-14 11 views

Répondre

4

ok, je suppose que je l'ai trouvé. Cela devrait fonctionner pour tout oledb et c'est sth. J'aime:

public static List<string> getKeyNames(String tableName, DbConnection conn) 
    { 
     var returnList = new List<string>(); 


     DataTable mySchema = (conn as OleDbConnection). 
      GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, 
           new Object[] {null, null, tableName}); 


     // following is a lengthy form of the number '3' :-) 
     int columnOrdinalForName = mySchema.Columns["COLUMN_NAME"].Ordinal; 

     foreach (DataRow r in mySchema.Rows) 
     { 
      returnList.Add(r.ItemArray[columnOrdinalForName].ToString()); 
     } 

     return returnList; 
    } 
+1

Vous avez sauvé ma journée tellement. Comment une solution si utile n'a pas d'utilisation documentée que je puisse trouver est au-delà de moi. – Faber75

Questions connexes