SqlCommand getEmp = new SqlCommand( "SELECT EmployeeID, Photo "+ "FROM Employees "+ "WHERE LastName = @lastName "+ "AND FirstName = @firstName", _conn); getEmp.Parameters.Add("@LastName", SqlDbType.NVarChar, 20).Value = plastName; getEmp.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = pfirstName; FileStream fs; // Writes the BLOB to a file (*.bmp). BinaryWriter bw; // Streams the BLOB to the FileStream object. int bufferSize = 100; // Size of the BLOB buffer. byte[] outbyte = new byte[bufferSize]; // The BLOB byte[] buffer to be filled by GetBytes. long retval; // The bytes returned from GetBytes. long startIndex = 0; // The starting position in the BLOB output. string emp_id = ""; // The employee id to use in the file name. // Open the connection and read data into the DataReader. _conn.Open(); SqlDataReader myReader = getEmp.ExecuteReader(CommandBehavior.SequentialAccess); while (myReader.Read()) { // Get the employee id, which must occur before getting the employee. emp_id = myReader.GetInt32(0).ToString(); // Create a file to hold the output. fs = new FileStream("employee" + emp_id + ".bmp", FileMode.OpenOrCreate, FileAccess.Write); bw = new BinaryWriter(fs); // Reset the starting byte for the new BLOB. startIndex = 0; // Read the bytes into outbyte[] and retain the number of bytes returned. retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize); // Continue reading and writing while there are bytes beyond the size of the buffer. while (retval == bufferSize) { bw.Write(outbyte); bw.Flush(); // Reposition the start index to the end of the last buffer and fill the buffer. startIndex += bufferSize; retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize)
解决方案 »
- 实现类似google搜索框那样的效果
- DataView里如果合并表头字段
- 弹出对话框?
- 用的是From 认证,,用后台管理员登陆 后,,但前台会员登陆却自动退出了?
- 谁会asp.net写硬盘加密
- 如何在TABLECELL中同时显示背景图片和文字?
- 动网论坛中主题后页的分页用Asp.Net(c#)如何实践,而且点击前面的+号可以开合,给个思路吧?
- 高分求教!Datagrid与CheckBox混合使用!(请高手指点,特别是脚本高手)
- 自定义控件中如何将子控件的属性提升为父控件的属性
- 如何用文件流方式读EXCEL文件
- 请问有没有xml的在线编辑器,就像html在线编辑器那样的
- 高人救我,不然被老板开除了,急!
可以做一个ActiveX控件实现此功能。