I'm new to C# and I have successfully created an application that stores personal data in access database, however I want to include a picture which is in a picturebox, to save it in the table, along with other information I have already saved

in essence, I want to save everything (personal details and a picture) in to the table at a click of a btnsave (button)

can someone help :,(

Thanking you in advance!!!!


Ms-Access database - You may preserve binary data (picture file or any other file) using OLE Object field type.

Following code might help you to understand how to store binary data into a database.

string file=@"x:\aa\image.png";
byte []content=System.IO.File.ReadAllBytes(file);

OledbConnection cn=new OledbConnection("...connection string ..");
// Emp (eno number, ename text(30), photo OLE object)
OledbCommand cmd=new OledbCommand("insert into emp values (?,?,?)",cn);

cmd.Parameters.Add("?", System.Data.OleDb.OleDbType.Integer, 4, "eno");
cmd.Parameters.Add("?", System.Data.OleDb.OleDbType.VarChar, 30, "ename");
cmd.Parameters.Add("?", System.Data.OleDb.OleDbType.Binary, content.Length, "photo");

cmd.Parameters[0].Value = 1;
cmd.Parameters[1].Value = "mosesmasuku";
cmd.Parameters[2].Value = content;


This article has been dead for over six months. Start a new discussion instead.