1. 将图片转为二进制存入数据库
string road = Application.StartupPath;
int index = road.LastIndexOf("bin");
string roadsub = road.Substring(0, index);
string roadNew = roadsub + "Resources\\Me.jpg";
System.IO.FileStream fs = new System.IO.FileStream(roadNew, FileMode.OpenOrCreate, FileAccess.Read);
byte[] fileByte = new byte[fs.Length];
fs.Read(fileByte, 0, (int)fs.Length);
int j = -1;
string sqlcommandText = @"insert into Picture (PContent)values(@pcontent)";
j = SqlHelper.ExecuteNonQuery(sqlcommandText, new SqlParameter("@pcontent", SqlDbType.Image) { Value = fileByte});
2.将二进制取出,转为图片显示
这篇博客介绍了如何将图片转换为二进制数组并存储到数据库中,以及如何从数据库中取出二进制数据,然后转换回图片。主要涉及文件流操作、SQL插入和查询,以及图片的保存和显示。
1671

被折叠的 条评论
为什么被折叠?



