zoukankan
html css js c++ java
将文件以二进制形式存储到Sql Server中
/DatSet读取文件/
#region
/DatSet读取文件/
/**/
///
<summary>
///
根据aaId,使用DataSet 读取**文件内容,还原恢复。
///
</summary>
///
<param name="ioId">
**的ID号
</param>
///
<param name="tableName">
表名
</param>
///
<param name="fieldName">
存储**文件内容的字段
</param>
public
bool
ReadFileOutFormSqlServer(
int
ioId,
string
tableName,
string
fieldName)
{
bool
flag
=
false
;
object
tempfileName
=
null
;
string
strSql
=
"
select fullpath,
"
+
fieldName
+
"
from
"
+
tableName
+
"
where infoID=
"
+
infoId;
DataSet ds
=
new
DataSet();
Database database
=
new
Database(p_sqlConnString);
try
{
ds
=
database.DBDataSet(strSql);
byte
[] tmpFile
=
null
;
foreach
(DataRow dr
in
ds.Tables[
0
].Rows)
{
if
(dr[
0
]
!=
DBNull.Value)
{
tempfileName
=
dr[
0
];
tmpFile
=
(
byte
[])dr[
1
];
}
}
ds.Dispose();
if
(tmpFile
!=
null
)
{
string
fileName
=
tempfileName.ToString();
FileInfo fi
=
new
System.IO.FileInfo(fileName);
if
(
!
fi.Exists)
{
//
新建文件
using
(FileStream fstream
=
fi.Create())
{
int
length
=
tmpFile.Length;
fstream.Write(tmpFile,
0
,tmpFile.Length);
fstream.Close();
flag
=
true
;
}
}
else
{
using
(FileStream fs
=
fi.OpenWrite())
{
int
length
=
tmpFile.Length;
fs.Write(tmpFile,
0
,tmpFile.Length);
fs.Close();
flag
=
true
;
}
}
}
}
catch
(Exception err)
{
throw
err;
}
finally
{
database.Close();
}
return
flag;
}
#endregion
/***保存文件***/
#region
/***保存文件***/
/**/
///
<summary>
///
保存文件到SQL Server数据库中
///
</summary>
///
<param name="RRR">
**文件类
</param>
///
<param name="tableName">
表名
</param>
///
<param name="fieldName">
存储**文件内容的字段
</param>
public
bool
SaveIntoSqlServer(RRR accredit,
string
tableName,
string
fieldName)
{
bool
flag
=
false
;
//
保存文件到SQL Server数据库中
string
fileName
=
accredit.FullPath;
FileInfo fi
=
new
FileInfo(fileName);
if
(fi.Exists)
{
SqlConnection cn
=
null
;
try
{
byte
[] dData
=
null
;
//
读文件,放入buffer
using
(FileStream fs
=
fi.OpenRead())
{
dData
=
new
byte
[fi.Length];
int
nReadLength
=
fs.Read(dData,
0
,(
int
)(fi.Length));
}
string
sqlStr
=
"
insert into
"
+
tableName
+
"
(ioID,path,cTime,
"
+
fieldName
+
"
) values(
"
+
accredit.IoID
+
"
,'
"
+
accredit.Path
+
"
','
"
+
accredit.CTime
+
"
',@file)
"
;
cn
=
ConnectToSqlSever();
if
(cn.State
==
0
) cn.Open();
SqlCommand cm
=
new
SqlCommand(sqlStr,cn);
cm.Parameters.Add(
"
@file
"
,dData);
cm.ExecuteNonQuery();
cm.Dispose();
flag
=
true
;
}
catch
(Exception err)
{
throw
err;
}
finally
{
cn.Close();
}
}
return
flag;
}
#endregion
数据字段为varbinary
查看全文
相关阅读:
如何使用命令行备份SAP HANA数据库
Rootkit介绍
web渗透测试基本步骤
IIS服务器的安全保护措施
渗透测试的流程
Kali Linux之常见后门工具介绍
中间人攻击(MITM)之数据截获原理
口令破解工具
常见渗透测试工具集成系统简介
Kali Linux之使用SET快捷生成钓鱼网站方法
原文地址:https://www.cnblogs.com/flashicp/p/746136.html
最新文章
ABAP-FTP-执行
ABAP-FTP-配置
ABAP-IDOC配置
洗礼灵魂,修炼python(85)-- 知识拾遗篇 —— 深度剖析让人幽怨的编码
洗礼灵魂,修炼python(84)-- 知识拾遗篇 —— 网络编程之socket
网络互联技术(4)——计算机网络常识、原理剖析
洗礼灵魂,修炼python(82)--全栈项目实战篇(10)—— 信用卡+商城项目(模拟京东淘宝)
洗礼灵魂,修炼python(81)--全栈项目实战篇(9)—— 购物商城登录验证系统
洗礼灵魂,修炼python(80)--全栈项目实战篇(8)—— 计算器
洗礼灵魂,修炼python(79)--全栈项目实战篇(7)—— 多级目录菜单之地址管理系统升级版
热门文章
洗礼灵魂,修炼python(78)--全栈项目实战篇(6)—— 多级目录菜单之地址管理系统
iPhone投影
SUSE 图形化界面/How to enable/disable AS Java Safe Mode
Maintenance Planner calculate SPs by manual
Check Kernel version of J2EE Engine
12/14
2690036
测试HANA的真实案例
1950261
SAP HANA HDBSQL命令
Copyright © 2011-2022 走看看