Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to Get Primary Key From the Table Return From Database

How to Get Primary Key From the Table Return From Database

Scheduled Pinned Locked Moved Database
databasehelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    N a r e s h P a t e l
    wrote on last edited by
    #1

    Hi Friends, I need the Primary Key of the Table return from DataBase. Eg: I am useing the following code: DataTable dt=new DataTable(); dt=GetDataTable(); DataColumn[] columns; columns =dt.PrimaryKey; for (int col = 0; col < columns.Length; col++) { ///Process the Primary Key } But the above code-dt.PrimaryKey always returns dimansion[0] means nothing. Is there any idea regarding this. Please help. Thanks in advance. :rose::rose::rose::rose::rose::rose::rose::rose::rose::rose: :rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:

    Naresh Patel

    B 1 Reply Last reply
    0
    • N N a r e s h P a t e l

      Hi Friends, I need the Primary Key of the Table return from DataBase. Eg: I am useing the following code: DataTable dt=new DataTable(); dt=GetDataTable(); DataColumn[] columns; columns =dt.PrimaryKey; for (int col = 0; col < columns.Length; col++) { ///Process the Primary Key } But the above code-dt.PrimaryKey always returns dimansion[0] means nothing. Is there any idea regarding this. Please help. Thanks in advance. :rose::rose::rose::rose::rose::rose::rose::rose::rose::rose: :rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose::rose:

      Naresh Patel

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      declare @TableName varchar(128) select @TableName = '**tablename**' select c.COLUMN_NAME from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , INFORMATION_SCHEMA.KEY_COLUMN_USAGE c where pk.TABLE_NAME = @TableName and CONSTRAINT_TYPE = 'PRIMARY KEY' and c.TABLE_NAME = pk.TABLE_NAME and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME


      I Love SQL

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups