首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
128
问题
如何通过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
程序员面试
相关试题推荐
Theimmunesystemisequalincomplexitytothecombinedintricaciesofthebrainandnervoussystem.Thesuccessoftheimmune
TruthinadvertisingisaconceptcentraltotheAmericanfreemarketeconomicsystem.Accordingtothistheory,companiesthat
Writealettertothedirectorofthelibraryinyouruniversity,givingsomeadviceonhowtoimprovethelibraryservice.You
删除字符串中的数字并压缩字符串(神州数码以前笔试题),如字符串”abc123de4fg56”处理后变为”abcdefg”。注意空间和效率。(下面的算法只需要一次遍历,不需要开辟新空间,时间复杂度为O(N))
从当前界面开始,对“C:\我的图片”文件夹设置共享。
请打开"计算器"应用程序,利用科学型模式将十六进制的ABC转换为二进制。
对于PPoint中的视图模式,以下说法错误的是()。A.幻灯片浏览视图下不能设置放映方式B.幻灯片视图注重于对幻灯片的文本和对象进行详细操作C.每种视图模式在演示文稿的制作和显示中有不同的作用D.大纲视图便于查看和编排演示文稿的大纲
在foxpro中定义数据库结构时,字段名的宽度最多可以是()。A.2B.4C.10D.16
请利用“外观和主题”窗口,设置屏幕保护为“字幕”,文字为“全国专业技术人员计算机应用能力考试中,请移动鼠标开始”字体为“黑体”,字号为“72”,颜色为“浅绿色”(请按题目的顺序操作)。
请对工作簿Book1设置密码123456,同时对其结构进行保护。
随机试题
这个标志是何含义?
交流伺服电动机的负载一定时,控制电压越高,转速越高。()
单纯性肛瘘仅有一个外口,直通入齿线上肛隐窝之内口者:单纯性肛瘘只有内口而无外口者:
塌落度表示塑性混凝土的()。
在我国,下列不属于政策性银行的是()。
基金管理公司内部控制的独立性原则是指( )。
任何单位和个人不得转借、转让、代开发票。()
α、β是实系数方程χ2+2χ+2=0的两个虚根,则它们在复平面上对应的向量夹角的正弦值为().
如果将所有中国人按照生日(不考虑年份,只考虑月、日)来排序,那么使用下列排序算法中(40)算法最快。
Tounderstandthemarketingconcept,itisonlynecessarytounderstandthedifferencebetweenmarketingandselling.Nottooma
最新回复
(
0
)