小弟刚学C#.在做一个相册管理器(WinForm的,把图片存SQL中)..相册一般是可以预览图片的..但偶不知道怎么弄.忘各位大哥指点...

解决方案 »

  1.   

    把图片保存到数据库,用image图片格式保存,然后写查询语句,
    用byte[] image = (byte[])SqlCommand .ExecuteScalar ();
    接收返回的东西  最后读出来就行了
      

  2.   

    HOW TO:在 Visual C# 中直接将一个图片从数据库复制到 PictureBox 控件
    http://support.microsoft.com/kb/317701/zh-cn
      

  3.   

    string sqlstr="select img from .....";
    SqlConnection con=new  SqlConnection ("server=.;....");
    con.open();
    SqlCommand cmd=new SqlCommand(sqlstr,con);
    SqlDataReader reader=cmd.ExcuReader();//ExcuReader();忘了怎么拼写了
    byte [] bytes=null;
    while(reader.read())
    {
       bytes=(byte[])reader["img"];
    }
    reader.close();
    con.close();
    stream s=new MemoryStream(bytes);
    Btimap bp=new btimap(s);
    this.picture1.image=bp;
    //后与有些字母大小写不正确,但思路正确,一路顺风!
      

  4.   

    请看我的这篇小博:
    http://blog.csdn.net/ki1381/archive/2007/03/04/1520535.aspx
      

  5.   

    byte[] image = (byte[])SqlCommand .ExecuteScalar ();
      

  6.   

    存放图片路径在SQL中,读出来以后把那个路径赋给一个图片控件,就行嘛
      

  7.   

    先把图像数据库取出来生成一张图片(在服务器端)再指定图像的url
                        SqlConnection conn = Db.Createconn();//数据库连接
                        conn.Open();
                        SqlCommand cmd = new SqlCommand("select * from  picture where id=" + count + "", conn);
                        string serverfile = Server.MapPath("") + "\\temppic\\" + count + ".jpg";
                        //Response.Write(serverfile);
                        FileStream fs = new FileStream(serverfile, FileMode.OpenOrCreate, FileAccess.Write);
                        BinaryWriter bw = new BinaryWriter(fs);                    SqlDataReader myReader = cmd.ExecuteReader();
                        while (myReader.Read())
                        {
                            bw.Write((byte[])myReader["pic"]);
                            break;
                        }
                        bw.Close();
                        myReader.Close();
                        this.Image1.Visible = true;
                        this.Image1.ImageUrl = "\\temppic\\" + count + ".jpg";
      

  8.   

    分少了点,copy给你,稍改一下~private void LoadImg()
    {
         SqlDbClass db = new SqlDbClass();
         SqlDataReader dr = db.ReaderData("select top 1 * from 签名");
         if (dr.Read())
         {
              Byte[] byteBLOBData = new Byte[0];
              byteBLOBData = (Byte[])dr.GetValue(0);
              MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
              s1.Image = Image.FromStream(stmBLOBData);          byteBLOBData = (Byte[])dr.GetValue(1);
              stmBLOBData = new MemoryStream(byteBLOBData);
              s2.Image = Image.FromStream(stmBLOBData);
          }
          dr.Close();
          db.Clear();
    }
      

  9.   

    SQL里面保存图像,当数据比较多的时候会严重影响速度!数据库定义一个image格式就可以保存,不过想要预览也必须把数据读出来