首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
155
问题
如何通过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
程序员面试
相关试题推荐
在金山网镖中添加一个端口过滤规则,其中端口为3080,协议为TCP,类型为远程,操作为禁止。
在当前窗口界面中,根据“添加打印机”向导,安装网络打印机,输入名称为“\\192.168.18.18\MicrosoftXPSDocumentWriter”。
从当前界面开始,到“电话和调制解调器的选项”中,将系统中的标准56000bps调制解调器删除。
从当前界面开始,对“C:\我的图片”文件夹设置共享。
设置DOS窗口为“快速编辑模式”。
若按下Shift键同时用鼠标分别单击幻灯片中的标题、文本和图片对象,则()。A.仅最后单击的对象被选中B.三个对象被同时选中C.仅标题对象被选中D.仅图形对象被选中
对于PPoint中的视图模式,以下说法错误的是()。A.幻灯片浏览视图下不能设置放映方式B.幻灯片视图注重于对幻灯片的文本和对象进行详细操作C.每种视图模式在演示文稿的制作和显示中有不同的作用D.大纲视图便于查看和编排演示文稿的大纲
Dreamweaver的视图(View)菜单中,Grid→settings表示______。A.选择计量系统来设定标尺单位B.显示一个应用当前设置的背景网格C.使插入对象与最近的对齐设置对齐D.进行网格设置
在PPoint中,要添加或改变幻灯片中的对象链接,可选择“幻灯片放映”菜单中的()命令。A.动作设置B.预设动画C.幻灯片切换D.自定义放映
请在当前幻灯片中的图形前添加一个形状,并输入“技术部”。
随机试题
下列为窗口事件的是()。
对于公共秩序,我国《涉外民事关系法律适用法》采用的立法模式为()
A、windB、kindC、findD、mindAA项划线部分发[i],而B、C、D三项划线部分发[ai],因此选A项。
不属于麻醉清醒期的是
女性,38岁,偶然发现右乳有一肿块,黄豆大,质硬,手术切除,病理诊断为导管内癌,其组织学改变是
下列关于要素饮食的说法,错误的是
依照《矿山安全法》的规定,有下列哪些行为之一的,责令改正,可以并处罚款;情节严重的,提请县级以上人民政府决定责令停产整顿;对主管人员和直接责任人员由其所在单位或者上级主管机关给予行政处分()。
下列属于现阶段进入代办股份转让系统进行转让股票的有( )。
无光的条件下也可以看到固有色。()
Wecanseehoweveryphilosopherreflectsthesociallifeofhisday.PlatoandAristotle,intheslave-owningsocietyofancien
最新回复
(
0
)