Does your table *know* what the primary key is? (Are you fetching the
schema with keys?)
No, apparently I'm not. I am getting a "table does not have a primary
key" exception. This is a simplified version of the schema I used to
autogenerate the class:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="TideStations" elementFormDefault="qualified"
xmlns="
http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="
http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="
http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
microsoft-com:xml-msdata">
<xs:element name="Stations">
<xs:complexType>
<xs:sequence>
<xs:element name="Station_ID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="Description" type="xs:string" />
.. many rows removed here..
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Station_ID is the primary key, but I think I will have to make that
explicit somewhere in here, won't I? I've been trying to suss out the
syntax for that but so far no luck...
By "doesn't work" do you mean it doesn't find the row?
No it throws an exception, described above.
Can you produce a short but complete example program which demonstrates
the problem?
No, I don't think I'm up to that, actually. What I've got, in a nutshell,
is this. I have a Datamanager singleton class (thanks to you), which
returns an instance of my typed dataset like this:
DataManager dm = DataManager.Instance;
TideStations st = dm.TideStationsDS;
//which is just a property whose getter establishes
//the connection and fills the dataset.
This is working okay, because I have used dataviews to get at what I want
from this, but now I want to retrieve a record directly knowing the
primary key value. So, for testing purposes, I am trying to retrieve the
record with the primary key of 526. I use this code:
int key = 526;
TideStations.StationsRow row = (TideStations.StationsRow)
st.Stations.Rows.Find( key );
But as I mentioned above ( and should have mentioned in my first post )
it is cacking because the primary key hasn't been defined in the typed
dataset.
So my real question should be
How do I define my primary key in an xsd so that xsd.exe will generate
the typed dataset using it?
Thanks
Marc