首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
156
问题
如何通过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
程序员面试
相关试题推荐
______isthecenterofourplanetarysystemwasadifficultconcepttograspintheMiddleAges.
ForAmerica’schildrentheeducationsystemisoftenliterallyalottery.ThatisthemainmessageofanewdocumentaryaboutAm
[A]Updateyourbudget[B]Submitachangeofaddressform[C]Bookacleaningservicebeforehand[D]Scheduleawalk-t
执行下面代码后:
数据库的优化设计?
在邮件中设置图片背景。
在Google搜索引擎中搜索多个关键词“office”,“WPS”。
若按下Shift键同时用鼠标分别单击幻灯片中的标题、文本和图片对象,则()。A.仅最后单击的对象被选中B.三个对象被同时选中C.仅标题对象被选中D.仅图形对象被选中
请打开“计算器”应用程序,利用科学型模式将十进制的1234转换为十六进制。
请对工作簿Book1设置密码123456,同时对其结构进行保护。
随机试题
企业上网是网络营销最基本的方式。()
古代九针中主要用于浅刺皮肤泻血,治头身热症,的是古代九针中主要用于揩摩体表,治分肉间气滞,不伤肌肉的是
女,48岁,反复咳嗽、胸闷、气喘30年。平素口服氨茶碱及“止咳祛痰”中药治疗,症状控制不理想。近1周来症状再次出现。查体:P86次/分,R24次/分。双肺可闻及散在哮鸣音。诊断为“支气管哮喘”。动脉血气分析示:pH7.46,PaCO232mmHg,
甲有限责任公司因经营不善而长期亏损,现金流严重不足。经查甲公司现有资产2100万元,负债3800万元,其中欠乙商业银行2000万元贷款已经到期不能清偿。乙商业银行将甲公司诉至人民法院,并申请对甲公司财产采取保全措施。甲公司现拟申请破产,股东会专门向公司法律
下列哪些选项表现了法律移植的必然性和必要性?()
宪法附则是指宪法对于特定事项需要特殊规定而作出的附加条款。下列关于宪法附则的法律效力的表述中正确的是:()
确定悬臂浇筑段前段标高应考虑的因素有()。
生漆
公共财政的法制化,要求( )。
Theroughguidetomarketingsuccessusedtobethatyougotwhatyoupaidfor.Nolonger.Whiletraditional"paid"media—suc
最新回复
(
0
)