C#怎么用二进制流存储图片到Sql Server中.?

2024-11-19 01:57:03
推荐回答(1个)
回答1:

//定义将图片转化为长二进制代码的函数getphoto()
public Byte[] getphoto(string photopath){
string str = photopath;
FileStream file = new FileStream(str, FileMode.Open,
FileAccess.Read);
Byte[] bytBLOBData = new Byte[file.Length];
file.Read(bytBLOBData, 0, bytBLOBData.Length);
file.Close();
return bytBLOBData;
if (this.pictureBox1.Image != null){
sql1 = sql1 + ",Photo";