tags:

views:

23

answers:

2

Hi,

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

+1  A: 

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.

sh_kamalh
Although I am sure this will work (because MSDN says so), I won't be able to use it as I will have either change the DataAdapter for my entire project or write another method/class for just running this one query. I found another way to make this work. But I will still mark this as answer because my original question did not specify the constraints that I just listed. Thanks for taking time to answer my query.
Ak
A: 

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!

Ak