110,533
社区成员
发帖
与我相关
我的任务
分享
private void DownloadImage(string FileID)
{
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection())
{
conn.ConnectionString = ".....";
conn.Open();
using(System.Data.SqlClient.SqlCommand command=conn.CreateCommand())
{
command.CommandText=string.Format("select ImageSize,Image from tablexxx where id='{0}'", FileID);
System.Data.SqlClient.SqlDataReader reader=command.ExecuteReader();
try
{
if(reader.Read())
{
int size=reader.GetInt32(0);
byte[] buffer=new byte[size];
reader.GetBytes(1,0,buffer,0,size);
this.Response.BinaryWrite(buffer);
}
}
catch(Exception ex)
{
this.Response.Write(ex.Message);
}
finally
{
reader.Close();
}
}
conn.Close();
}
}