[英]How to save image in SQL image type column from picturebox without mentioning pics url?
I have a picturebox
where custom image is drawn when mouse button is pressed now i want to save that image in SQL's image type column
. 我有一个图片
picturebox
,现在按下鼠标按钮时便会绘制自定义图像,我想将该图像保存在SQL的image type column
。
I did search for saving but theres nothing for saving a pic from picturebox to sql image type column without url . 我确实搜索了保存,但是没有什么可以将图片从picturebox保存到没有url的sql图像类型列中。
You could probably use this solution . 您可能可以使用此解决方案 。 Tho you would have to save the picturebox image to a jpeg first.
您首先必须将图片框图像保存为jpeg。
byte[] image = File.ReadAllBytes("D:\\11.jpg");
Edited: 编辑:
//without saving the image to a physical file
MemoryStream stream=new MemoryStream();
pictureBox1.Image.Save(stream,System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic=stream.ToArray();
SqlCommand sqlCommand = new SqlCommand("INSERT INTO imageTest (pic_id, pic) VALUES (1, @Image)", yourConnectionReference);
sqlCommand.Parameters.AddWithValue("@Image", image);
sqlCommand.ExecuteNonQuery();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.