是人事数据库中的照片,再在领导要用这些照片,能不能按人名存成文件。如有现成的代码,请给我!
解决方案 »
- 通过函数select到的列,如何做为where语句的条件?
- ORACLE 多表查询
- oracle ora-12535 tns operation time out
- 关于触发器多用还是少用的问题讨论
- JAVA连接oracle问题,找不到oracle.jdbc.driver.OracleDriver
- 【 初级问题 】 关于触发器, 100分奉上?
- 如何用like实现如windows操作系统中?的查询效应
- 为什么不能通过数据库连接串访问另一个数据库中的表?
- 游标没关闭会导致数据库内存泄露吗?数据库服务器每天掉100内存,晕!
- 这样的触发器怎么做呀?
- 简单又有点难道的统计分组问题
- insert 中包含 & 字符, 出错
MSDN中的例子// 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();