我在数据库中的一条记录中存了二进制数据,大概有几十兆。现在不想一次把所有的数据都读到内存里,想分成若干个大小为64K的数据块,再依次读出。请问该如何做
解决方案 »
- Task任务并行的问题
- C# 有三个窗体,第一个是主窗体,运行时第二个窗体填充到第一个窗体,点击第二个窗体的按钮怎样让第三个填充到第一个窗体中
- 关于用正则匹配换行符的问题
- 数据转换
- WebForm中如用在GridView中显示几万条记录?
- 请问怎么在在js里去掉freetextbox的空格 ,在线,马上给分,谢谢拉
- 为什么在c#的com+事务中,声明并打开一个vb的数据库连接(ADODB.Connection),需要2秒时间?
- 求点链接自动生成html页面的方法(最好附源程序)
- 请问如何监控某个端口是否被连接,谢谢
- 这是什么意思?我怎么看不懂!!!!!!!!!不会那么夸张吧!
- sql 中的 + 单引号 双引号 什么意思 ?? 谢谢
- .net web项目安装与部署
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();
}
}
http://community.csdn.net/Expert/topic/4756/4756451.xml?temp=.7671015
那个 dr.GetBytes 不知道是不是一次把所有数据全读到内存里,然后再一段段返回给用户。如果是这样,就没有什么意义了