首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
107
问题
如何通过ADO.NET读取数据库中的图片?
选项
答案
// Assumes that connection is a valid SqlConnection object. SqlCommand command = new SqlCommand("SELECT pub_id, logo FROM pub_info", connection); // Writes the BLOB to a file (*.bmp). FileStream stream; // Streams the BLOB to the FileStream object. BinaryWriter writer; // Size of the BLOB buffer. int bufferSize = 100; // The BLOB byte[] buffer to be filled by GetBytes. byte[] outByte = new byte[bufferSize]; // The bytes returned from GetBytes. long retval; // The starting position in the BLOB output. long startIndex = 0; // The publisher id to use in the file name. string pubID = ""; // Open the connection and read data into the DataReader. connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()){ // Get the publisher id, which must occur before getting the logo. pubID = reader.GetString(0); // Create a file to hold the output. stream = new FileStream("logo" + pubID + ".bmp", FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(stream); // Reset the starting byte for the new BLOB. startIndex = 0; // Read bytes into outByte[] and retain the number of bytes returned. retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize); // Continue while there are bytes beyond the size of the buffer. while (retval == bufferSize) { writer.Write(outByte); writer.Flush(); // Reposition start index to end of last buffer and fill buffer. startIndex += bufferSize; retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize); } // Write the remaining buffer. writer.Write(outByte, 0, (int)retval - 1); writer.Flush(); // Close the output file. writer.Close(); stream.Close(); }// Close the reader and the connection. reader.Close(); connection.Close();
解析
转载请注明原文地址:https://kaotiyun.com/show/GxmZ777K
0
程序员面试
相关试题推荐
定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。要求函数min、push以及pop的时间复杂度都是O(1)。
.net中读写数据库需要用到哪些类?他们的作用
在邮件中设置图片背景。
将金山网镖应用程序规则列表中的应用程序QQ2009删除。
请打开"计算器"应用程序,利用科学型模式将十六进制的ABC转换为二进制。
对于PPoint中的视图模式,以下说法错误的是()。A.幻灯片浏览视图下不能设置放映方式B.幻灯片视图注重于对幻灯片的文本和对象进行详细操作C.每种视图模式在演示文稿的制作和显示中有不同的作用D.大纲视图便于查看和编排演示文稿的大纲
请打开“计算器”应用程序,利用科学型模式将十进制的1234转换为十六进制。
论IT服务规划设计IT服务规划设计处于IT服务生命周期的前期,如果前期未进行有效的规划设计,那么仓促而就的IT服务就难以满足客户的真正需求,可能造成IT服务可用性降低、客户满意度低下等问题。为确保有效做好IT服务规划设计,服务供方在IT服务规划设计过程中
IT服务团队建设周期中,组建期有四个关键步骤,其前后顺序不能改变。现将次序打乱为:①确定目标②稳定核心成员③了解现状④建立团队价值观下面______是其正确的排序方式。
随机试题
男性,60岁。2型糖尿病病史5年,无冠心病、高血压病史,查血脂LDL-C为3.9mmol/L,对该患者的血脂应如何干预
金锁固精丸的组成药物不包括
颈动脉搏动,多见于()
题39图所示系统的表达式为()。
关于商品编码2002101000和2002909000所对应的货物,以下表术正确的有:
企业享受的下列税收优惠中,属于企业会计准则规定的政府补助的是()。
下列各项中,有权制定税收规章的税务主管机关有()。
[2011年第33题]受多元文化和价值观的冲击,甲国居民的离婚率明显上升。最近一项调查表明,甲国的平均婚姻存续时间为8年。张先生为此感慨,现在像钻石婚、金婚、白头偕老这样的美丽故事已经很难得。人们淳朴的爱情婚姻观一去不复返了。以下哪项如果为真,最可能表明张
Readtheextractbelowfromabookaboutcorporateplanning.ChoosethecorrectwordtofilleachgapfromA,B,CorDonthe
Onhearingthenewsthatherfatherdiedofacaraccident,she______tears.
最新回复
(
0
)