Setting the Primary key of a DataTable

  • Thread starter Thread starter KJ
  • Start date Start date
K

KJ

I have a Datatable with 1 datarow in it. When I try to set the primary
key I get an error back saying that the columns in the datatable are
not unique.


How do I fix it?
 
You need a unique value to set a primary key. As I am not sure how you are
getting dupes, I am not sure how to progress. Here is a guess.

You are probably using a query that pulls from multiple tables. This is
creating dupes due to the joins. You can do one of the following things, if
this is true.

1. Add further conditions on the SQL join statement or use DISTINCT when you
pull the values (not sure the syntax if this is not SQL Server).
2. Pull each table as a separate DataTable and add relationships to your
DataSet.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top