首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
101
问题
如何通过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
程序员面试
相关试题推荐
TruthinadvertisingisaconceptcentraltotheAmericanfreemarketeconomicsystem.Accordingtothistheory,companiesthat
ForAmerica’schildrentheeducationsystemisoftenliterallyalottery.ThatisthemainmessageofanewdocumentaryaboutAm
TheUnitedStatesInterstateHighwaySystemisaninfrastructurefeatofunprecedentedproportions.Notonlydoesitjoinallfi
"Thecatdoesnotofferservices,"WilliamBurroughswrote."Thecatoffersitself."Butitdoessowithunapologeticcontradict
根据委托(delegate)的知识,请完成以下用户控件中代码片段的填写:namespacetest{publicdelegatevoidOnDBOperate();publicclassUserControlBase
在百度中搜索“腊梅”图片。
不能显示和编辑备注内容的视图模式是()A.普通视图B.大纲视图C.幻灯片视图D.备注页视图
在PPoint中,()新幻灯片的占位符,可添加指定的对象,如图片等。A.左键单击B.右键单击C.左键双击D.右键双击
下列关于通信技术的叙述中,错误的是________。
信息系统的生命周期可以简化为立项、开发、运维及消亡四个阶段,()属于开发阶段的工作。
随机试题
简述深感觉传导通路的组成、走行。
患者男,78岁。因“摔倒致腰部疼痛,不能自主行走3个月,加重7天”来诊。7天前因弯腰不当导致症状加重,腰背部刺痛,咳嗽时疼痛加重。查体:腰椎后凸畸形,第1、第4腰椎椎体棘突压痛和叩击痛明显。腰椎正侧位片:腰1、腰4椎体变扁,椎体高度减低,上缘不同程度凹陷;
简述多器官功能障碍综合征的原因和诱因。
患者,女,人工流产术后4天.寒战、高热,小腹疼痛拒按,阴道出血时多时少,色暗如败酱,气味臭秽,口干喜饮,舌质红,苔黄腻,脉弦数。治疗最佳选方是( )
在生产性工程建设中,设备工器具购置费用占工程造价比重的增大,意味着()。
单元格A2输入了数值70,单元格B2存放了公式=IF(A2>90,“A”,IF(A2>80,“B”,“C”)),那么B2显示的是()。
可与国际单位制单位并用的我国法定计量单位有()。
影响问题解决的定势包括()
ThesixteenthinternationalAIDSconferenceopenedonSundayinToronto,Canada.Morethantwenty-fourthousanddelegatesfromo
A、IthelpstheBritishsavetime.B、TheBritishlikedoinghouseworkverymuch.C、ItwillhelptheBritishwiththeirwork.D、Th
最新回复
(
0
)