110,534
社区成员
发帖
与我相关
我的任务
分享
truncate table dali --清表
insert dali values(1,0x,'jpg','1') --插记录用于以后写binary数据
exec sp_textcopy '127.0.0.1','sa','xxx','test','dali','MyImage','c:\1.jpg','where ID=1','I' --将 c:\1.jpg以二进制方式写入表dali的id=1的行的myimage字段
SqlConnection cn=new SqlConnection("server=127.0.0.1;uid=sa;pwd=xxx;database=test");
cn.Open();
SqlCommand cmd=new SqlCommand("select myimage from dali",cn);
int bufferSize = 100;
byte[] outbyte = new byte[bufferSize];
long retval;
long startIndex = 0;
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
while (dr.Read())
{
startIndex = 0;
retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize);
while (retval == bufferSize)
{
Response.BinaryWrite(outbyte);
startIndex+= bufferSize;
retval = dr.GetBytes(0, startIndex, outbyte, 0, bufferSize);
}
Response.BinaryWrite(outbyte);
}
dr.Close();
cn.Close();