Populating a DataTable from a DataAdapter - Wrong Column Selected as Primary Key

I populate an object datatableusing dataadapterpulling data from a database MS-SQL. For some reason, the wrong column is set as the primary key in the datatable. I tried FillSchemaand to MissingSchemaAction.AddWithKeyno avail.

The correct primary key is correctly defined in the SQL server DB schema and is supported by a unique index PK_xwithout clustering.

The column selected as the primary key using the data adapter is a unique column supported by a clustered unique index.

These are only two columns in the table.

How does DataAdapter retrieve table schema from SQL? I polled the sys tables (sys.tables, sys.index_columns, sys.indexes) and they indicate the correct primary key scheme. What gives?

+5
source share
1 answer

"If a unique clustered index is defined in a column or columns of a SQL Server table, and the primary key constraint is defined in a separate set of columns, then the column names in the cluster index will be returned. Returns the name or column names of the primary key, use the query hint with the SELECT statement, which indicates primary key index name For more information about setting prompts, see the prompt (Transact-SQL) .

http://msdn.microsoft.com/EN-US/library/152bda9x(v=VS.110,d=hv.2).aspx

+1
source

All Articles