title: C# DataSet validation from XML schema
body: <p>I have a xml schema. I want to populate a DataSet and validate it using this schema.</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>DataSet package = new DataSet();
  StringReader schemaResourceReader = new StringReader(PackageValidationLibrary.Properties.Resources.myPackage);
  package.ReadXmlSchema(schemaResourceReader);
  
  
  package.Tables["Table1"].Rows.Add(packageDetail.date,packageDetail.code,packageDetail.amount,packageDetail.place,"0");
  package.Tables["Table2"].Rows.Add("0","0");
  foreach (Cek data in recordList){
      package.Tables["Table3"].Rows.Add(data.Serial, data.Code, data.Branch, data.ValidityDate, "0");
  }
  </code></pre>
  
  <p>Using the code above I can load data but I cannot validate it although dataset imports the schema.</p>
  
  <p>I tried to get xml string using package.GetXml() method and reload the xml again. Then I got exceptions.</p>
  
  <p>How can I validate this table? Thanks.</p>
  
  <hr>
  
  <p><strong>EDIT</strong>
  As I understand from answers and comments it is not possible to validate while populating the dataset. Then I read the xml from dataset and loaded it with the configuration given below.</p>
  
  <pre class="lang-cs prettyprint-override"><code>_schema = XmlSchema.Read(new StringReader(PackageValidationLibrary.Properties.Resources.TakasPaketi), new ValidationEventHandler(ValidationEventHandler));
                  XmlReaderSettings _settings = new XmlReaderSettings();
                  _settings.Schemas.Add(_schema);
                  _settings.ValidationType = ValidationType.Schema;
                  XmlReader vreader = XmlReader.Create(stream, _settings);
  </code></pre>