zoukankan
html css js c++ java
从SQL Server中读写大数据列。
public
static
void
Main()
{
//写入大对象到
SqlServer
FileStream fs
=
new
FileStream(
"
C:\\test.bmp
"
,FileMode.OPen,FileAccess.Read);
BinaryReader br
=
new
BinaryReader(fs);
SqlConnection conn
=
new
SqlConnection(
"
server=localhost;uid=sa;pwd=sa;database=northwind
"
);
string
cmdText
=
"
UPDATE EMPLOYEES
"
+
"
SET Photo=@image where EmployeeId=1
"
;
SqlCommand cmd
=
new
SqlCommand(cmdText,conn);
cmd.Parameters.Add(
"
@image
"
,SqlDbType.Image);
cmd.Parameters[
"
@image
"
].Value
=
br.ReadBytes((
int
)br.BaseStream.Length);
conn.Open();
int
i
=
cmd.ExecuteNoQuery();
//
从SQL Server中读取大对象
string
cmdtext
=
"
SELECT employeeid,photo
"
+
"
from employees where employeeid = 1
"
;
SqlCommand cmd2
=
new
SqlCommand(cmdtext,conn);
FileStream rfs;
BinaryWriter rbw;
long
numread;
long
startIndex;
int
buffSize
=
4096
;
byte
[] buff
=
new
byte
[buffSize];
conn.Open();
SqlDataReader rdr
=
cmd.ExecuteReader(CommandBehavior.SequentialAccess);
if
(rdr.Read())
{
int
empid
=
rdr.GetInt32(
0
);
fs
=
new
FileStream(
"
c:\\mypic.bmp
"
,FileMode.OpenOrCreate,FileAccess.Write);
bw
=
new
BinaryWrite(fs);
startIndex
=
0
;
numread
=
rdr.GetBytes(
1
,startIndex,buff,
0
,buffSize);
while
(numread
==
buffSize)
{
bw.Write(buff);
bw.Flush();
startIndex
+=
buffSize;
numread
=
rdr.GetBytes(
1
,startIndex,buff,buffSize);
}
bw.Write(buff);
bw.Flush();
bw.Close();
fs.Close();
}
rdr.Close();
conn.Close();
}
查看全文
相关阅读:
scp命令详解
linux下不同服务器间数据传输(rcp,scp,rsync,ftp,sftp,lftp,wget,curl)
详解代理自动配置 PAC
linux卸载
VMware里克隆出来的CentOS Linux device eth0 does not seem to be present, delaying initialization
CentOS系统更换软件安装源yum
kali开启禁止或删除ssh 开机启动
7天玩转 ASP.NET MVC
C#高级编程42章 MVC
C#高级编程(32章)ADO.net
原文地址:https://www.cnblogs.com/wxx/p/188969.html
最新文章
【Error】IOError: [Errno 22] invalid mode
Nginx禁止域名恶意解析
Ubuntu 无法获得锁
Ubuntu下配置舒服的Python开发环境
pip 使用总结
【Error】 : make 不是内部或外部命令,也不是可运行的程序
Python 序列化pickle/cPickle模块整理
python2.x和3.x在同一个服务器(windows下)互不影响解决办法(不要用开发工具ide安装模块,容易混乱)
Python __len__()、__reversed__()、__contains__()
selenium远程linux服务搭建(一)原理
热门文章
linux下使用升级后的稳定版python2.7时不能正常使用
selenium远程linux服务搭建(二)linux搭建
用PyCharm执行测试成功但无法生成HTMLTestRunner报告
Python Selenium unittest+HTMLTestRunner实现 自动化测试及发送测试报告邮件
百度音乐爬虫代码_实现
解决selenium参数化读取excel时为float类型的问题
python模块初识
vmstat命令详解
Linux中的特殊权限s、t、i、a
iptables规则的删除-怎么删除一条已有的iptables规则
Copyright © 2011-2022 走看看