0
votes

I am using System.Data.IDbCommand to query a table that has a primary key. My query joins it with other tables and fetches me multiple records with the same value in the primary key column but different values in other joined columns and this is the intended behaviour.

However, IDbCommand.ExecuteReader().GetSchemaTable() shows that the reader's internal schema table has a primary key on that column. Now, if I try to load this reader into a System.Data.DataTable (plain old DataTable, not typed), it throws a constraint violation exception (obviously because it is trying to insert the same value for the primary key column).

Is there a way I can instruct ExecuteReader() to ignore the source schema or not enforce the constraints?

Other information: This is .Net 2.0.

Thanks in advance

2
The resulting table shouldn't have that primary key. What provider are you using?svick

2 Answers

2
votes

Can you use something like

DataTable result = new DataTable();
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
adapter.Fill(result);

Initialize the command with your query and use the correct provider.

0
votes

Guys, I found a workaround. This is not a solution though. I modified my query to bring that column from some other table where it was present as a foreign key column referring to the primary key column of my original table.

Cheers!