C# 如何从VisualStudio将图像插入数据库

C# 如何从VisualStudio将图像插入数据库,c#,database,image,insert,picturebox,C#,Database,Image,Insert,Picturebox,我在VisualStudio中创建了一个数据库表PHOTOS。它有id(int)、文件名(string)和照片文件类型图像。我制作了一个表格,将PictureBox中当前的Image插入数据库。当然,因为我非常缺乏经验,这是行不通的。 如何从c#中的picturebox将图像插入数据库?谢谢你们的回答,我知道这个代码是错误的,但我希望它能让你们知道我在做什么 SqlCeCommand command = new SqlCeCommand("insert into photos(id, phot

我在VisualStudio中创建了一个数据库表PHOTOS。它有id(int)、文件名(string)和照片文件类型图像。我制作了一个表格,将PictureBox中当前的Image插入数据库。当然,因为我非常缺乏经验,这是行不通的。 如何从c#中的picturebox将图像插入数据库?谢谢你们的回答,我知道这个代码是错误的,但我希望它能让你们知道我在做什么

SqlCeCommand command = new SqlCeCommand("insert  into photos(id, photo ,filename) values (@id, @blob,@filename)", connection);
command.Parameters.AddWithValue("@blob", pictureBox1.Image);//fileBytes);
command.Parameters.AddWithValue("@filename", textBox1.Text);
command.Parameters.AddWithValue("@id", Int32.Parse(textBox2.Text));

您需要将图像转换为字节数组以将其插入数据库。这里有一条关于如何做到这一点的线索:除此之外,你已经有了大致的想法。您只需使用字节[]作为参数的值