Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Storing in Database problem

Back to Forum: Tech Off
  • User profile image
    Deactivated User

    Comment removed at user's request.

  • User profile image
    littleguru

    I'm guessing that you are using XmlSerializer to serialize the class. You could a MemoryStream as the stream where to store the XML to. You could use that MemoryStream then to store the bytes to the database Smiley

    I hope this helps.

  • User profile image
    Deactivated User

    Comment removed at user's request.

  • User profile image
    littleguru

    You should post a little bit of your code Smiley Makes it easier to understand what you actually trying to do.

  • User profile image
    littleguru

    I tried this and it worked without problems.

    [Serializable]
    public class Foo
    {
        private int _prop1;
        private string _prop2;

        public string Prop2
        {
            get { return _prop2; }
            set { _prop2 = value; }
        }

        public int Prop1
        {
            get { return _prop1; }
            set { _prop1 = value; }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Foo f = new Foo();
            f.Prop1 = 1;
            f.Prop2 = "test";

            MemoryStream stream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, f);

            // Holds the result of the serialization.
            byte[] bytes = stream.ToArray();

            // Deserialize the bytes array.
            f = (Foo)formatter.Deserialize(new MemoryStream(bytes));
        }
    }

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.