Esempio n. 1
0
        static void Main(string[] args)
        {
            SqlXmlCommand cmd = new SqlXmlCommand(connectionString);

            cmd.CommandText   = "Person.Contact";
            cmd.CommandType   = SqlXmlCommandType.XPath;
            cmd.SchemaPath    = "Person.Contact.xsd";
            cmd.ClientSideXml = true;
            cmd.RootTag       = "Person.Contact";

            SqlXmlAdapter da = new SqlXmlAdapter(cmd);
            DataSet       ds = new DataSet();

            try
            {
                // Fill the dataset
                da.Fill(ds);
                // Make some change
                ds.Tables[0].Rows[1]["LastName"] = "Unabel";
                // Update the data back to the database.
                da.Update(ds.GetChanges());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        public void Update(IDataSet dataSet)
        {
            _sberrors = new StringBuilder();

            //Hold temporary xml in memory.
            MemoryStream mem = new MemoryStream();

            //Validate only changes to the dataset
            dataSet.GetChanges().WriteXml(mem, XmlWriteMode.IgnoreSchema);
            //Reset current position in the temporary memory representation.
            mem.Position = 0;
            //Read schema.
            XmlSchema sch;

            //We don't need the full path because the FileStream class can reads relative paths.
            using (FileStream fs = new FileStream(dataSet.SchemaFile, FileMode.Open))
            {
                sch = XmlSchema.Read(fs, new ValidationEventHandler(this.OnValidation));
                sch.Compile(new ValidationEventHandler(this.OnValidation));
            }

            //Validate incoming data.
            XmlValidatingReader reader = new XmlValidatingReader(new XmlTextReader(mem));

            reader.Schemas.Add(sch);
            reader.ValidationType          = ValidationType.Schema;
            reader.ValidationEventHandler += new ValidationEventHandler(this.OnValidation);

            //Read to end and check errors afterwards.
            while (reader.Read())
            {
            }

            if (_sberrors.Length != 0)
            {
                throw new ArgumentException(_sberrors.ToString(), "BaseDataSet");
            }

            SqlXmlCommand cmd = new SqlXmlCommand(_connection);

            cmd.CommandType = SqlXmlCommandType.DiffGram;
            cmd.SchemaPath  = dataSet.SchemaFile;
            SqlXmlAdapter ad = new SqlXmlAdapter(cmd);

            //Update database with DataSet data.
            ad.Update(dataSet.GetState());
        }
Esempio n. 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     da.Update(ds);
 }