}
prgLoader.Value = 100;
lblShowPercent.Text = prgLoader.Value.ToString() +
"%"
;
btnOk.Text =
"关闭"
;
}
}
else
{
if
(intCount == 0)
{
strSelect = strTargetSelect;
sqlcmd.CommandText = strSelect;
bytContent =
new
byte
[intLength];
bytContent = sqlcmd.ExecuteScalar()
as
byte
[];
fs.Write(bytContent,0,intLength);
}
else
{
int
i = 0;
bytContent =
new
byte
[intBlock];
while
(i < intCount)
{
strSelect =
"declare @content varbinary(16) "
;
//再sql中声明获取目标image列内容的句柄变量
strSelect += strTargetHandle;
//获取句柄
//锁定并读取指定长度的数据
strSelect +=
" readtext "
+ strTableName +
"."
+ strColumnName +
" @content @start @count HOLDLOCK"
;
if
(i == 0)
{
//添加@start和@count变量,分别表偏移变量和取的长度
sqlcmd.Parameters.Add(
"@start"
,System.Data.SqlDbType.Int).Value = 0;
sqlcmd.Parameters.Add(
"@count"
,System.Data.SqlDbType.Int).Value = intBlock;
}
else
{
sqlcmd.Parameters[
"@start"
].Value = i * intBlock;
sqlcmd.Parameters[
"@count"
].Value = intBlock;
}
sqlcmd.CommandText = strSelect;
bytContent = sqlcmd.ExecuteScalar()
as
byte
[];
fs.Write(bytContent,0,intBlock);
++i;
}
//将剩余的字节写入流
int
intResidual = intLength % intBlock;
if
(intResidual > 0)
{
strSelect =
"declare @content varbinary(16) "
;
//再sql中声明获取目标image列内容的句柄变量
strSelect += strTargetHandle;
//获取句柄
//锁定并读取指定长度的数据
strSelect +=
" readtext "
+ strTableName +
"."
+ strColumnName +
" @content @start @count HOLDLOCK"
;
bytContent =
new
byte
[intResidual];
sqlcmd.Parameters[
"@start"
].Value = intCount * intBlock;
sqlcmd.Parameters[
"@count"
].Value = intResidual;
sqlcmd.CommandText = strSelect;
bytContent = sqlcmd.ExecuteScalar()
as
byte
[];
fs.Write(bytContent,0,intResidual);
}
}
}
bytContent =
null
;
fs.Close();
}
catch
{
state = 0;
System.IO.File.Delete(strPath);
bytContent =
null
;
fs.Close();
return
false
;
}
state = 0;
return
true
;
}
本文转自 BruceAndLee 51CTO博客,原文链接:http://blog.51cto.com/leelei/194147,如需转载请自行联系原作者