首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
68
问题
如何通过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
"Thecatdoesnotofferservices,"WilliamBurroughswrote."Thecatoffersitself."Butitdoessowithunapologeticcontradict
列举ADO.NET中的五个主要对象,并简单描述
添加一个新的类型是计算机管理员的用户John
从当前界面开始,到“电话和调制解调器的选项”中,将系统中的标准56000bps调制解调器删除。
请在当前幻灯片中插入一个组织结构图,其中第一层与第二层之间有一个助手图框。
将E-R图转换到关系模式时,实体与联系都可以表示成______。
信息技术的根本目标是()。
任何一个团队从开始组建到最终达到绩效要求,需要一个周期。依据塔克曼群体发展模型,结合IT服务管理工作特性,将团队建设周期分为四个阶段,它们分别是(未按正确次序排列):①风暴期②表现期③组建期④规范期团队建设周期的正确排序为______。
随机试题
患者,男性,40岁,胸闷伴全身无力2个月余。胸部CT提示:左前上纵隔不规则软组织肿块影,密度均匀,边界欠清楚,略呈分叶状,纵隔内未见肿大淋巴结。为预防术后肌无力危象,下列哪些措施是正确的
某共同盗窃案件,有犯罪嫌疑人甲和乙2人,人民检察院在审查起诉过程中,甲逃跑,乙在押。那么该检察院的审查起诉工作应当如何进行()。
对员工培训SA8000管理体系的主要目的是()。
表象是指客观事物不在面前时,人们在头脑中出现的关于事物的形象。从信息加工的角度来讲,表象是指当前不存在的物体或事件的一种知识表征,这种表征具有鲜明的形象性。根据以上定义,下列中现象属于表象的是:
公车上书[华南师范大学2021年研]
在运行阶段,要在文本框Text1获得焦点时选中文本框中所有内容,如图1所示,对应的事件过程是()。
考生文件夹下有一个数据库文件“samp2.accdb”,其中存在已经设计好的表对象“tAttend”、“tEmployee”和“tWork”,请按以下要求完成设计。创建一个查询,查找并显示项目经费在10000元以下(包括10000元)的“项目名称”
Hurricanesareviolentstormsthatcausemillionsofdollarsinpropertydamageandtakemanylives.Theycanbeextremelydange
Sevenpeoplewerearrestedbecause
Whichofthefollowingbeststatesthemainideaofthepassage?Asitisusedinthesecondparagraphofthepassage,theword
最新回复
(
0
)