Page 1 of 1

Saving and loading annotations (XMP) from database

Posted: Thu Mar 25, 2010 7:14 pm
by pikob1
Hi,

I have this code for loading annotations from database:

Code: Select all

            AnnotationCollection collection;
            XmlDocument doc = new XmlDocument();
            cmd.CommandText = "SELECT ... FROM ... WHERE Id=" + id + ";";
            cmd.Connection = con2;
            object obj = cmd.ExecuteScalar();

            doc.InnerXml = obj.ToString();

            collection = annotationViewer1.Annotations[0];
            collection.Load(doc);
and this for saving them:

Code: Select all

            XmlDocument doc = annotationViewer1.Annotations[0].Save();
            cmd.CommandText = "UPDATE ... SET ...=@xmldata WHERE Id=" + id + ";";
            SqlParameter sqlparam1 = new SqlParameter("@xmldata", SqlDbType.VarChar);
            sqlparam1.Value = doc.InnerXml;
            cmd.Parameters.Add(sqlparam1);
            cmd.Connection = con2;
            cmd.ExecuteNonQuery(); // dodanie rekordu zdjęcia
Saving operation is ok.

The problem is with loading annotations from database.
They appear in doc variable and in InnerXml, but collection doesn't load the data nor display saved annotations.

Could anyone help?

Re: Saving and loading annotations (XMP) from database

Posted: Fri Mar 26, 2010 1:06 pm
by pikob1
Ok, I solved it.

The field in database should be of Xml type.

And saving should use SqlDbType.Ntext type.