首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
148
问题
如何通过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://www.kaotiyun.com/show/GxmZ777K
0
程序员面试
相关试题推荐
"Thecatdoesnotofferservices,"WilliamBurroughswrote."Thecatoffersitself."Butitdoessowithunapologeticcontradict
定义栈的数据结构,要求添加一个min函数,能够得到栈的最小元素。要求函数min、push以及pop的时间复杂度都是O(1)。
在Google搜索引擎中搜索多个关键词“office”,“WPS”。
在金山网镖中添加一个端口过滤规则,其中端口为3080,协议为TCP,类型为远程,操作为禁止。
启动操作系统自带的Intemet连接防火墙。
Dreamweaver的视图(View)菜单中,Grid→settings表示______。A.选择计量系统来设定标尺单位B.显示一个应用当前设置的背景网格C.使插入对象与最近的对齐设置对齐D.进行网格设置
在“幻灯片浏览视图”模式下,不允许进行的操作是()A.幻灯片移动和复制B.幻灯片切换C.幻灯片删除D.设置动画效果
请打开“计算器”应用程序,利用科学型模式将十进制的1234转换为十六进制。
将E-R图转换到关系模式时,实体与联系都可以表示成______。
信息技术的根本目标是()。
随机试题
—________,please?—Mywatchshowsitis8:30now.
易卜生的“社会问题剧”主要有
引起气性坏疽的致病菌是
提取挥发油常用的方法是()。
关于中和面,下列说法正确的是_________。
根据《房产测绘管理办法》,以下关于房产测绘的说法中,正确的是()。
1.背景材料:某高速公路第五施工合同段地处城郊,主要工程为路基填筑施工。其中K48+010~K48+328段原为路基土方填筑,因当地经济发展和交通规划需要,经各方协商,决定将该段路基填筑变更为(5×20+3×36+5×20)m预应力钢筋混凝土箱梁
按下表设计进行实验,分组后,在相同的适宜条件下培养8~10小时,并对实验结果进行分析。下列叙述正确的是()。
Ifyouhadbeenlesscautious,youmayhavebeenwiser.
AlloverEurope,andinNorthAmerica,there’relakesandforestswhicharedeador(71)andthe(72)isthoughttobeacid
最新回复
(
0
)