将图像保存在数据库Visual Studio中 [英] Save image in database visual studios
本文介绍了将图像保存在数据库Visual Studio中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何将图像保存到数据库中。我知道我们必须先将图像转换为字节,然后将其保存在数据库中。我已将数据类型设置为数据库中的字节。我需要有关如何在Visual Studio 2010 C#中执行此操作的示例项目或代码示例。
谢谢
i would like to know how to save an image into database. I know that we have to convert the image into a byte first and then save it in the database. I have set the data type to byte in the database. I need example projects or code samples on how to go about doing this in visual studios 2010 C#. Thank You
推荐答案
如果要查找图像
FileInfo fInfo = new FileInfo(yourPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
byte[] imageData = br.ReadBytes((int)numBytes);
请根据对象类型尝试以下行
try with these lines based on object type
command.Parameters.Add(new SqlParameter("@Image", (object)imageData));
这篇关于将图像保存在数据库Visual Studio中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文