111,096
社区成员




DataTable dt=Global.Query("select max(id) from t_discount_card where photo is not null");
int totalcount=int.Parse(dt.Rows[0][0].ToString());//保存大的图片ID
int id=0;
string sql="";
for(;id<totalcount;)
{
if(id==0)
sql="select top 20 id,photo from t_discount_card where photo is not null order by id";
else
sql="select top 20 id,photo from t_discount_card where photo is not null and id>"+id.ToString()+"order by id";
if(totalcount==id) //如果是最后一个图片,则退出
return;
DataTable dt1=Global.Query(sql);
for(int count=0;count<dt1.Rows.Count;count++)
if(dt1.Rows[count]["photo"]!=System.DBNull.Value)
{
byte[] imgdata=((byte[])(dt1.Rows[count]["photo"]));
if(imgdata!=null && imgdata.Length>100)
{
MemoryStream myStream=new MemoryStream();
foreach(byte a in imgdata)
{
myStream.WriteByte(a);
}
if(File.Exists(Application.StartupPath+@"\pic\"+dt1.Rows[count]["id"].ToString()+".jpg"))
File.Delete(Application.StartupPath+@"\pic\"+dt1.Rows[count]["id"].ToString()+".jpg");
Image.FromStream(myStream).Save(Application.StartupPath+@"\pic\"+dt1.Rows[count]["id"].ToString()+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
myStream.Close();
myStream=null;
}
id=int.Parse(dt1.Rows[count]["id"].ToString());
}
dt1.Dispose();
GC.Collect();
}
Image img=Image.FromStream(myStream);
img.Save(Application.StartupPath+@"\pic\"+dt1.Rows[count]["id"].ToString()+".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();