怎样才可以把已经存入到数据库的图片保存在硬盘上那? 数据库中有3个自动ID,自动增长,pic/Image类型、存的图片信息、picSize/int类型、图片大小怎样才可以保存在本地那、? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //示例代码取pubs中pub_info表中的图像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(); }} 关于C#中 通过比较Build之后生成的Dll文件,判断源码是否修改过的解决办法。 ??连接数据库的问题??? 用程序怎样抓取浏览器 http get 请求的数据 新手咨询数组问题?? 关于按序取出HashTable的值 如何将DataTable中数据Insert到SQL Server的非空表中?谢谢! 80分求:导出Excel问题! 在线急 如何在C#项目中实现插件功能(外挂功能模块)?最好有示例代码. 常见的小问题:string类型怎么转成int(float)... SQL语句太长就查不出数据了吗? 如何调用系统函数??
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();
}
}