首页 > 其他分享 >blob((binary large object),二进制大对象)转化字节流下载附件

blob((binary large object),二进制大对象)转化字节流下载附件

时间:2023-03-08 09:01:01浏览次数:38  
标签:binary fs sdr object large blob new null conn

Byte[] blob = null;  FileStream fs = null;  const string sConn = "server=(local);Initial  Catalog=Northwind;UID=ctester;PWD=password";  try {  SqlConnection conn = new SqlConnection(sConn);  SqlCommand cmd = new SqlCommand("SELECT Picture FROM Categories WHERE  CategoryName='Builder'", conn);  cn.Open();  SqlDataReader sdr = cmd.ExecuteReader();  sdr.Read();   blob = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))];  sdr.GetBytes[0, 0, blob, 0, blob.Length);  sdr.Close();  conn.Close();  fs = new FileStream("c:\\Builder.doc", FileMode.Create, FileAccess.Write);   fs.Write(blob, 0, blob.Length);  fs.Close();  } catch (SqlException e){  Console.WriteLine("SQL Exception: " + e.Message);  } catch (Exception e) {  Console.WriteLine("Exception: "+ e.Message);  }

标签:binary,fs,sdr,object,large,blob,new,null,conn
From: https://www.cnblogs.com/997icu/p/17190644.html

相关文章