1

Just starting a project for a course I'm doing and to get data for the database we must create our accessor methods which I found fine but I must create these for pictures that are blobs in my database anyone know how to best do this?

these are what I have so far and the way our lecturer wants them...

namespace ClassLibrary
{
    class Advert
    {
        public String Name
        {
            get { return Name; }
            set { Name = value; }
        }

        public String Genre
        {
            get { return Genre; }
            set { Genre = value; }
        }

        public String Console
        {
            get { return Console; }
            set { Console = value; }
        }

        public String Description
        {
            get { return Description; }
            set { Description = value; }
        }

        public double Price
        {
            get { return Price; }
            set { Price = value; }
        }
    }
}
4
  • How about a byte[]? Then convert it to an image in code... Essentially what a blob is is a byte[]. Commented Nov 22, 2014 at 22:27
  • 9
    Your getters and setters are infinitely recursive. Commented Nov 22, 2014 at 22:28
  • 3
    This is not going towork. All your properties use the same property as their backing fields. You will get a stack overflow... Commented Nov 22, 2014 at 22:29
  • ...but for images, you can use the Bitmap type. When reading and writing to the database, you could use a memory stream. The buffer property of memory stream is an array of byte. Commented Nov 22, 2014 at 22:32

1 Answer 1

2

Essentially what a blob is is a byte[]:

namespace ClassLibrary {
  public class Advert
  {
    public String Name { get; set; }
    public String Genre { get; set; }
    public String Console { get; set; }
    public String Description { get; set; }
    public double Price { get; set; }
    public byte[] MyImage { get; set; }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks i was actually looking at that but since this is the first time i was using images in a database i had to ask before i got down to the hard stuff and was totally wrong so thanks for your help
this link: stackoverflow.com/questions/7350679/… might help you with conversion of bitmap to/from byte[].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.