首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
129
问题
如何通过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
程序员面试
相关试题推荐
TheUnitedStatesInterstateHighwaySystemisaninfrastructurefeatofunprecedentedproportions.Notonlydoesitjoinallfi
Signslike"Pleaseratemefivestars"pointtoagrowingproblemwithbusinessesintheon-demandeconomyofapp-basedservices
[A]Updateyourbudget[B]Submitachangeofaddressform[C]Bookacleaningservicebeforehand[D]Scheduleawalk-t
ASP.NET能在那些系统中运行?
执行下面代码后:
下列叙述正确的是______A.通过“我的电脑”图标可以浏览和使用所有的计算机资源B.“我的电脑”是一个文件夹C.“回收站”用于存放被删除的对象,置入“回收站”中的对象在关机后自动消失D.用户可以在桌面上创建文件夹或快捷方式
在PPoint中,()新幻灯片的占位符,可添加指定的对象,如图片等。A.左键单击B.右键单击C.左键双击D.右键双击
请利用“外观和主题”窗口,设置屏幕保护为“字幕”,文字为“全国专业技术人员计算机应用能力考试中,请移动鼠标开始”字体为“黑体”,字号为“72”,颜色为“浅绿色”(请按题目的顺序操作)。
下列关于通信技术的叙述中,错误的是________。
任何一个团队从开始组建到最终达到绩效要求,需要一个周期。依据塔克曼群体发展模型,结合IT服务管理工作特性,将团队建设周期分为四个阶段,它们分别是(未按正确次序排列):①风暴期②表现期③组建期④规范期团队建设周期的正确排序为______。
随机试题
组织文化的核心层是()
下列《长恨歌》诗句中,属于移情于景的是
髓袢利尿药:
按病因分类,外科疾病可分为________、________、________、________、________、________和________。
既能治风寒头痛,又能治疗鼻渊的药物是
具有下列哪一项条件的材料不能作为抗α、β辐射材料?[2006年第056题]
从18世纪到19世纪末,英国一直处于国际分工中心国家的地位,在资本主义世界对外贸中一直独占鳌头。()
简述评估的总结。
Whatisthepurposetoeatsomegarlicaccordingtothepassage?Itcan______.Whatisalsoagoodmethodtohelpyousleep
Ofallthe【C1】______ofagoodnight’ssleep,dreamsseemtobeleastwithinourcontrol.Indreams,awindowopensintoaworld
最新回复
(
0
)