I am filling a datatable
object through a dataadapter
pulling data from a MS-SQL
database. For some reason the wrong column is set as the primary key on the datatable. I have tried FillSchema
and MissingSchemaAction.AddWithKey
to no avail.
The correct primary key is defined properly in the SQL server DB schema & is backed by a non clustered unique index PK_x
.
The column selected as the primary key by the dataadapter is a unique column backed by a clustered unique index.
These are the only two columns in the table.
How does DataAdapter retrieve the table schema from SQL? I have interrogated the sys tables (sys.tables, sys.index_columns, sys.indexes) and they indicate the proper primary key schema. What gives?
"If a unique clustered index is defined on a column or columns in a SQL Server table and the primary key constraint is defined on a separate set of columns, then the names of the columns in the clustered index will be returned. To return the name or names of the primary key columns, use a query hint with the SELECT statement that specifies the name of the primary key index. For more information about specifying query hints, see Query Hint (Transact-SQL)."
http://msdn.microsoft.com/EN-US/library/152bda9x(v=VS.110,d=hv.2).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With