如题,谢谢。

解决方案 »

  1.   

    //读取pubs数据库logo字段
    using System;
    using System.IO;
    using System.Data;
    using System.Data.SqlClient;class BLOBDemo
    {
    [STAThread]
    static void Main(string[] args)
    {
    SqlConnection cn = new SqlConnection("Data Source = (local);Integrated Security = SSPI;Initial Catalog=pubs");
    SqlCommand cmd = new SqlCommand("Select pub_id,logo FROM pub_info", cn); FileStream fs;
    BinaryWriter bw; //缓冲区大小
    const int bufferSize = 100;
    byte [] outByte = new byte[bufferSize];
    //GetBytes返回的字节数量
    long retval;
    //BLOB输出的起始位置
    long startIndex = 0; string pub_id = ""; cn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess); while(dr.Read())
    {
    pub_id = dr.GetString(0); fs = new FileStream("logo" + pub_id + ".bmp", FileMode.OpenOrCreate, FileAccess.Write);
    bw = new BinaryWriter(fs); startIndex = 0;

    do
    {
    retval = dr.GetBytes(1, startIndex, outByte, 0, bufferSize);
    // Console.WriteLine(retval.ToString());
    bw.Write(outByte);
    bw.Flush();
    startIndex += bufferSize;
    }while(retval == bufferSize); bw.Write(outByte, 0, (int)retval - 1);
    bw.Flush(); bw.Close();
    fs.Close();
    } dr.Close();
    cn.Close();
    }
    }
      

  2.   

    谢谢amandag(高歌) 的回复,我试试先。