数据库中二进制文件怎么样读取到文本框中啊

解决方案 »

  1.   

    private void getContain(string pgid)
    {
    int nBufferSize = 255;
    byte[] arrbyte = new byte[nBufferSize];
    MemoryStream objMemoryStream;
    BinaryFormatter objBinaryFormatter;
    SqlCommand comm = new SqlCommand();
    comm.Connection = new SqlConnection(ConfigurationSettings.AppSettings["connectionstring"]);
    comm.CommandText =       
    comm.Parameters.Add(new SqlParameter("@pgid", SqlDbType.Char,14));
    comm.Parameters["@pgid"].Value = pgid;
    comm.Connection.Open();
    SqlDataReader dr = comm.ExecuteReader();
    if (dr.Read())
    {
    titletxt.Value = dr["title"].ToString();
    arrbyte = (byte[])dr["contect"];
    objMemoryStream = new MemoryStream(arrbyte);
    objBinaryFormatter = new BinaryFormatter();
    cotain.Text = (string)objBinaryFormatter.Deserialize(objMemoryStream);
    objMemoryStream.Close();
    }
    comm.Connection.Close();  
    }