Hi,
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!!!!

Recommended Answers

All 2 Replies

Dear,

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;

cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.