多谢

解决方案 »

  1.   

    ADODataSet1.Fields.Fields[0].IsIndexField=true then...
      

  2.   

    for Index:=0 to DataSet.Fields.Count-1 do
    Dataset.fields.Fields[Index].IsIndexField=true
    begin
      //这里就是主键了
    end
    但是前提就是要保证你的控件的active是true的
      

  3.   

    如果是sql server的数据库的话sp_MStablekeys ‘表名’也是可以的
    oracle没有用过的 不知道有没有这个存储过程的
      

  4.   

    大师级都 为回答了1!!!HEHE!!!
      

  5.   

    SqlServer:  下面语句中的b.name列就会返回你的表的主键
    select b.name
    from sysobjects a,syscolumns b
    left outer join (select g.id,g.colid from sysindexes f,
    sysindexkeys g where f.id = g.id and f.indid = g.indid and f.indid > 0
    and f.indid < 255 and (f.status & 2048)<>0) h on b.id = h.id and b.colid = h.colid
    where a.id = b.id
    and a.id = object_id('你的表名')
    and h.id is not null
      

  6.   

    你要的是索引还是主键?一直没有想出来,想看看别人的回答,结果发现都是索引的,有没有办法隔离数据库来得到主键?就是说不管后台数据库是什么都能得到主键的办法?
    如果时oracle可以从user_objects里面查到,如果时sql server也可以从它的系统标结构里面查到,但是关键是每一中数据库存放主键的位置不一样,不知道delphi有没有办法可以得到,据说ado的metadata工具好像可以得到,不知道是否准确
      

  7.   

    Dataset.fields.Fields[Index].IsIndexField=true好象是指索引的
      

  8.   

    IsIndexField的确是索引。但是要主键,这个....这个...还在研究中。。
      

  9.   

    oracle中试试用这个语句,如果有多个主键,要循环取出
    select column_name from user_constraints uc,user_cons_columns ucc 
    where constraint_type = 'P' and uc.table_name = 表名 and uc.constraint_name = ucc.constraint_name
    表名自己指定,其它照写。然后fieldbyname('column_name')