I get the error "Table doesn't have a primary key." so how d开发者_JAVA百科o I set the primary keys, does it not do this when I call ReadXml() or have a missed a arg out??
MemoryStream msXml = new MemoryStream(byteArray);
DataSet dsXml = new DataSet();
dsXml.ReadXml(msXml);
string s = "123456789";
DataRow foundRow = dsXml.Tables["Accounts"].Rows.Find(s);
EDITED
Here is a basic example of the format of my xml file. How would I set primary keys for each CD?
Thanks
Thanks all for you help I managed to fingure it out. Example below worked for me if it helps anyone else.
DataSet dsXml = new DataSet();
dsXml.ReadXml(msXml);
DataTable tbl;
tbl = dsXml.Tables["Accounts"];
tbl.PrimaryKey = new DataColumn[] { tbl.Columns["Id"] };
You are reading XML data into your dataset, but not the Schema, which is where a PK would be defined.
The error is thrown when you use the Find method which requires a Pk, which is not defined.
Either define one manually after loading the data or save/load both xml and schema.
精彩评论