views:

40

answers:

0

When filling a DataSet, I am using the "AddWithKey" value for the DataAdapter's MissingSchemaAction. According to MSDN:

Adding schema information to a DataSet before filling it with data ensures that primary key constraints are included with the DataTable objects in the DataSet.

But, when I do the following:

DataColumn[] foo = TheDataSet.Tables["Table1"].PrimaryKey;

I get foo.Length of 0. Is there something more that I need to do besides this?:

string TheQuery = "SELECT * FROM Table1 LEFT OUTER JOIN Table2 ON Table1.EVENT_NUM = Table2.EVENT_USER_NUM;
using (SqlDataAdapter TheDataAdapter = new SqlDataAdapter(TheQuery, TheConnection)
{
    TheDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
    TheDataAdapter.Fill(TheDataSet, "Table1");
}

Note, if my query was:

string TheQuery = "SELECT * FROM Table1";

All would be fine. But, I don't get a PrimaryKey if there is a join. Is this even possible (to get the Primary key)?