/// 将文件流写入数据库
/// </summary>
/// <param name="filePath">存入数据库文件的路径</param>
/// <param name="id">数据库中插入文件的行标示符ID</param>
/// <returns></returns>
public
int
UploadFile(
string
filePath,
string
id)
{
byte
[] buffer =
null
;
int
result = 0;
if
(!
string
.IsNullOrEmpty(filePath))
{
String file = HttpContext.Current.Server.MapPath(filePath);
buffer = File.ReadAllBytes(file);
using
(SqlConnection conn =
new
SqlConnection(DBOperator.ConnString))
{
using
(SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText =
"update DomesticCompanyManage_Main_T set ZBDocumentFile = @fileContents where MainID ='"
+ id +
"'"
;;
cmd.Parameters.AddRange(
new
[]{
new
SqlParameter(
"@fileContents"
,buffer)
});
conn.Open();
result = cmd.ExecuteNonQuery();
conn.Close();
}
}
return
result;
}
else
return
0;
}