首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
如何通过ADO.NET读取数据库中的图片?
如何通过ADO.NET读取数据库中的图片?
admin
2019-03-29
153
问题
如何通过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
TheUnitedStatesInterstateHighwaySystemisaninfrastructurefeatofunprecedentedproportions.Notonlydoesitjoinallfi
TheUnitedStatesInterstateHighwaySystemisaninfrastructurefeatofunprecedentedproportions.Notonlydoesitjoinallfi
列举一下你所了解的XML技术及其应用
n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字)。当一个数字删除后,从被删除数字的下一个继续删除第m个数字。求出在这个圆圈中剩下的最后一个数字。
把个人的信息进行设置,显示图片“火箭发射”,与其他人共享网络摄像机功能。
从当前界面开始,对“C:\我的图片”文件夹设置共享。
在PPoint中,被选中对象虚框上的8个小方框称为()。A.尺寸控制点B.文本插入点C.有效区域范围D.选中对象标记
论IT服务规划设计IT服务规划设计处于IT服务生命周期的前期,如果前期未进行有效的规划设计,那么仓促而就的IT服务就难以满足客户的真正需求,可能造成IT服务可用性降低、客户满意度低下等问题。为确保有效做好IT服务规划设计,服务供方在IT服务规划设计过程中
信息系统项目生命周期中,内容最多、最繁杂的阶段是()。
随机试题
制造容易是模具设计的首要原则,然后再考虑保证冲压件质量和使用寿命。
简述出具无保留意见的审计报告的条件。
最能解释同工不同酬现象的是哪种道德观()
A.H2受体拮抗剂B.黏膜保护剂C.质子泵抑制剂D.抗酸剂E.多巴胺受体拮抗剂奥美拉唑
赵某因绑架罪被甲省A市中级法院判处死刑缓期两年执行,后交付甲省B市监狱执行。死刑缓期执行期间,赵某脱逃至乙省C市实施抢劫被抓获,C市中级法院一审以抢劫罪判处无期徒刑。赵某不服判决,向乙省高级法院上诉。乙省高级法院二审维持一审判决。此案最终经最高法院核准死刑
下列说法错误的是()。
设X~t(n),则下列结论正确的是().
为“评分”表的“分数”字段添加有效性规则:“分数必须大于等于0并且小于等于10”,正确的SQL语句是
A、 B、 C、 C句子是询问为什么没有给卡洛斯分配处理合同的任务的Why疑问句。
AlthoughBeethovencouldsitdownandcomposeeasily,hisreallygreatcompositionsdidnotcomeeasilyatall.Theycosthima
最新回复
(
0
)