我用winform做学生管理系统,有一个存图片,我存进去之后能取出来,但是修改的时候,修改完之后。发现修改过后的图片不能看,数据库里有显示二进制文件,求解
string sqlupdate = "Update StudentInfo Set Picture=@photo where StudentID='"+label14.Text.ToString()+"'";
SqlConnection con = new SqlConnection(Helper.sql);
con.Open();
SqlCommand command = new SqlCommand(sqlupdate, con);
command.Parameters.Add("@photo", SqlDbType.Image, convert(img).Length);
command.Parameters["@photo"].Value = convert(img);
int i = command.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("修改成功");
}
else
{
MessageBox.Show("修改失败");
}
con.Close();
//二进制转换
public byte[] convert(string photo)
{
FileStream file = new FileStream(photo,FileMode.Open,FileAccess.Read);
byte[] bytes = new byte[photo.Length];
file.Read(bytes, 0, bytes.Length);
file.Close();
return bytes;
}winform数据库
string sqlupdate = "Update StudentInfo Set Picture=@photo where StudentID='"+label14.Text.ToString()+"'";
SqlConnection con = new SqlConnection(Helper.sql);
con.Open();
SqlCommand command = new SqlCommand(sqlupdate, con);
command.Parameters.Add("@photo", SqlDbType.Image, convert(img).Length);
command.Parameters["@photo"].Value = convert(img);
int i = command.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("修改成功");
}
else
{
MessageBox.Show("修改失败");
}
con.Close();
//二进制转换
public byte[] convert(string photo)
{
FileStream file = new FileStream(photo,FileMode.Open,FileAccess.Read);
byte[] bytes = new byte[photo.Length];
file.Read(bytes, 0, bytes.Length);
file.Close();
return bytes;
}winform数据库
解决方案 »
- DataGridView 怎么根据内容调整行高
- 求C#进程间通信方法
- 旋转图形按中心还是质心?
- 求助 SQL CLR 事务嵌套
- 请教问题!
- 使用类GraphicsPath()画弧行边角的矩形窗体
- select的记录在datagrid里面显示格式的一点小问题
- 初级程序员如何从项目当中学到知识???
- Application has generated an exception that could not be handled.
- 请问怎样使用 Managed Extensions to C++ 来包装函数??
- 问下C# 调用 C++ 接口 问题 有点难度 请进
- System.Timer.Timer的lock争用问题
另附一个链接:http://www.cnblogs.com/sufei/archive/2010/09/24/1834054.html