Diligent achievement genius ...

业精于勤荒于嬉 行成于思毁于随 voiow博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将数据库存储的附件写到文件夹上面

Posted on 2009-12-21 13:00  voiow  阅读(194)  评论(0编辑  收藏  举报

SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123;database=am89resource");
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("", conn);
                    cmd.CommandText = "select * from picture where id='0331010009'";

                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        byte[] bytes = (byte[])dr["img"];
                        FileStream fs = new FileStream(Server.MapPath("//img//1.gif"), FileMode.Create, FileAccess.Write);
                        fs.Write(bytes, 0, bytes.Length);
                        fs.Flush();
                        fs.Close();
                    }
                    conn.Close();