I want to stores fotos use DB4o and a tried de following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Db4objects.Db4o;
using Db4objects.Db4o.Linq;
namespace imagemsDb4o
{
class Person
public class Person
{
public string Name { set; get; }
public byte foto { set; get; }
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
FileInfo fi = new FileInfo("c:\\test.yap");
if (fi.Exists)
fi.Delete();
pictureBox1.Load("c:\\sunset.jpg");
Person pers = new Person();
pers.Name = "Martin";
pers.bild = (System.Drawing.Bitmap)(pictureBox1.Image);
IObjectContainer db = Db4oFactory.OpenFile("c:\\test.yap");
db.Store(pers);
db.Commit();
db.Close();
}
private void button2_Click_1(object sender, EventArgs e)
{
Person suchpers = new Person();
suchpers.Name = "Martin";
IObjectContainer db = Db4oFactory.OpenFile("c:\\test.yap");
IObjectSet result = db.QueryByExample(suchpers);
Person gefunden = (Person)result.Next();
textBox2.Text = (string) gefunden.Name;
pictureBox2.Image = (byte) gefunden.bild;
db.Close();
}
}
}
It gives error when i click button2. What change must I make?