Dataset XML Reading Failed to enable constraint in c#

1

I have a dataset which was created using integrated VisualStudio designer with proper tables, fields and relations.

enter image description here

However I want to query for the events that are within a specific date, When I try to read the xml file

this.localDB1.ReadXml($"C:\\Users\\Mike\\source\\repos\\evnt\\evnt\\bin\\Debug\\user.xml");

when I use that code to read the xml file to the dataset I get the following exception

System.Data.ConstraintException
  HResult=0x8013192A
  Message=Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
  Source=System.Data
  StackTrace:
   at System.Data.DataSet.EnableConstraints()
   at System.Data.DataSet.set_EnforceConstraints(Boolean value)
   at System.Data.XmlDataLoader.LoadData(XmlReader reader)
   at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
   at System.Data.DataSet.ReadXml(String fileName)
   at EventManageWPF.View.AddEvent.<btn_save_Click>d__15.MoveNext() in    C:\Users\mike\source\repos\evnt\evnt\ViewEvent.cs:line 158

This is my XML file

<?xml version="1.0" standalone="true"?>
<LocalDB xmlns="http://tempuri.org/LocalDB.xsd">
<UserEvents>
<eventid>event1</eventid>
</UserEvents>
<EventDates>
<Id>-1</Id>
<startDate>2019-11-25T12:59:15.3809179+05:30</startDate>
<endDate>2019-11-25T13:59:15.1449851+05:30</endDate>
<UserEvents_eventid>event1</UserEvents_eventid>
</EventDates>
</LocalDB>

I'm new to c# so I'm unable to find a solution for this

c#
xml
dataset
asked on Stack Overflow Nov 25, 2019 by mike oconner

1 Answer

1

Make sure you are initializing the localDb1 before reading the XML file.

this.localDB1 = new localDB1()
this.localDB1.ReadXml($"C:\\Users\\Mike\\source\\repos\\evnt\\evnt\\bin\\Debug\\user.xml");
answered on Stack Overflow Nov 25, 2019 by Rasheen Ruwisha

User contributions licensed under CC BY-SA 3.0