How to Get Primary Key From the Table Return From Database
-
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
-
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
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