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();
}
查看全文
相关阅读:
北航软院2012级C#期末考试部分考题解答
题目1013:开门人和关门人(字符串处理)
char * 与char []探究理解
题目1017:还是畅通工程(最小生成树)
最小生成树(Prim算法+Kruskal算法)
题目1018:统计同成绩学生人数(hash简单应用)
GoogLeNet InceptionV2/V3/V4
Python库
卷积为什么如此强大?一文全解深度学习中的卷积
神经网络训练tricks
原文地址:https://www.cnblogs.com/wxx/p/188969.html
最新文章
BZOJ3530: [Sdoi2014]数数
BZOJ3172: [Tjoi2013]单词
BZOJ2351: [BeiJing2011]Matrix
BZOJ2938: [Poi2000]病毒
BZOJ1030: [JSOI2007]文本生成器
BZOJ3473: 字符串
解题:NOIP 2018 赛道修建
解题:洛谷3402 可持久化并查集
解题:ZJOI 2006 书架
解题:HNOI 2012 永无乡
热门文章
解题:ZJOI 2006 游戏排名系统
解题:洛谷3674 小清新人渣的本愿
解题:AHOI 2013 作业
解题:由乃OI 2018 五彩斑斓的世界
解题:APIO 2015 雅加达的摩天大楼
解题:洛谷1975 排队
题目1022:游船出租(hash简单应用)
北航软院2014级C#期末考试部分考题解答
北航软院2015级C#期末考试部分考题讲解
北航软院2013级C#期末考试部分考题解答
Copyright © 2011-2022 走看看